def translate_language(lan):
x = 0
out = str(lan)
while x < 1000:
recognizer = speech_recognition.Recognizer()
with speech_recognition.Microphone() as source:
audio = recognizer.listen(source)
text = recognizer.recognize_google(audio, language="en")
translator = googletrans.Translator()
translation = translator.translate(text, dest=out)
print(translation.text)
converted_audio = gtts.gTTS(translation.text, lang=out)
SpeakText(translation.text)
x = x + 1
I am passing language code to this function and store it in out variable by converting it into a string. When I use out variable for language it works fine but when I use it in dest, it raises error : invalid destination language. What should I do??
I have tried making it string value or removing it. T=when I use the same variable as language value it works fine but doesnot work with dest