我正在使用 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 telebot
import requests
from pydub import AudioSegment
import os
import io
from google.cloud import speech
from google.cloud.speech import enums
from google.cloud.speech import types
os.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")
繁星淼淼
相关分类