我正在使用 Windows 和 Python 3.8.3,并使用来自 Google Cloud Platform 的 Cloud Speech-to-Text API,每次保存我的代码时它都会指向一个错误“模块‘google.cloud.speech_v1.types’没有‘RecognitionAudio’成员”和“模块‘google.cloud.speech_v1.types’没有‘RecognitionConfig’成员”我查看了文档,唯一谈论的是 Python 2.7 之前的版本,这不适用于我,有人知道这个问题的解决方案吗?import telebotimport requestsfrom pydub import AudioSegmentimport osimport iofrom google.cloud import speechfrom google.cloud.speech import enumsfrom google.cloud.speech import typesos.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "./chatbotia-279018-759b32f57985.json"token = "1233361335:AAEO4qSTP6EraU6DvzU"bot = telebot.TeleBot(token)downloadAudio = "https://api.telegram.org/file/bot{token}/".format(token = token)@bot.message_handler(commands=['start'])def send_welcome(message): bot.reply_to(message, "Bem vindo ao bot de escrita, por favor mande um áudio 🔊 que lhe será retornado da mesma forma, mas em uma mensagem escrita📝") bot.reply_to(message, "qualquer duvida mande /help.")@bot.message_handler(commands=['help'])def send_help(message): bot.reply_to(message, " disque 190")@bot.message_handler(content_types=['voice'])def handlerAudio(message): #get audio from telegram messageVoice = message.voice #get download link audioPath = bot.get_file(messageVoice.file_id).file_path audioLink = downloadAudio+audioPath #download file audioFile = requests.get(audioLink) audioName = "audio.ogg" #save locally open(audioName, 'wb').write(audioFile.content) #convert format to .WAV AudioSegment.from_file(audioName).export("audio.wav", format="wav") sound = AudioSegment.from_wav("audio.wav") sound = sound.set_channels(1) #convert mono sound.export("audio.wav", format="wav")
1 回答
繁星淼淼
TA贡献1775条经验 获得超11个赞
在文档和Github 的 README中, 是从而不是types
从导入的。google.cloud.speech_v1
google.cloud.speech
你已经尝试过了吗?
编辑:经过进一步分析,错误似乎是来自 IDE 的警告。Google Cloud SDK 的导入机制经常导致 IDE 显示此类警告,但代码仍然有效。
添加回答
举报
0/150
提交
取消