我正在尝试构建自己的自动语音到文本翻译器,这是我到目前为止的代码...
import speech_recognition as sr
from googletrans import Translator
from textblob import TextBlob
translator = Translator()
speech = sr.Recognizer()
with sr.Microphone() as source:
print("say something!")
audio = speech.listen(source)
ToTranslate = speech.recognize_google(audio, language='ko')
Translate = ToTranslate ####^^####
print(Translate)
try:
print("The language used is: " )
print("You said: " + ToTranslate)
translation = translator.translate(ToTranslate).text
print("In english: " + translation)
except sr.UnknownValueError:
print("Sorry I can't understand you.")
except sr.RequestError:
print("Error")
如果我想让它自动检测语言,我该怎么办?