import speech_recognition as sr
from googletrans import Translator
def Listen():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
r.pause_threshold = 1
audio = r.listen(source,0,6)
try:
print("Regognizing...")
query = r.recognize_google(audio, language = "hi")
except:
return ""
query = str(query).lower()
return query
def TranslationHintoEng(Text):
line = str(Text)
translate = Translator()
result = translate.translate(line)
data = result.text
print(f"You : {data}")
return data
TranslationHintoEng("कैसा है जारविस मेरी आवाज आ रही है")
When i Run this:
PS E:\Coding\Python\AI -2\Pyttsx3 Hindi STT> & C:/Users/admin/AppData/Local/Programs/Python/Python310/python.exe "e:/Coding/Python/AI -2/Pyttsx3 Hindi STT/Body/Listen.py"
Traceback (most recent call last):
File "e:\Coding\Python\AI -2\Pyttsx3 Hindi STT\Body\Listen.py", line 35, in <module>
TranslationHintoEng("कैसा है जारविस मेरी आवाज आ रही है")
File "e:\Coding\Python\AI -2\Pyttsx3 Hindi STT\Body\Listen.py", line 30, in TranslationHintoEng
result = translate.translate(line)
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\site-packages\googletrans\client.py", line 182, in translate
data = self._translate(text, dest, src, kwargs)
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\site-packages\googletrans\client.py", line 78, in _translate
token = self.token_acquirer.do(text)
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\site-packages\googletrans\gtoken.py", line 194, in do
self._update()
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\site-packages\googletrans\gtoken.py", line 62, in _update
code = self.RE_TKK.search(r.text).group(1).replace('var ', '')
AttributeError: 'NoneType' object has no attribute 'group'
PS E:\Coding\Python\AI -2\Pyttsx3 Hindi STT>
I wanted it to translate the text, but when I am running it shows the atrribute error as shown above. If possible please help me and ya thats all and i am stuck here for an hour now I am on python 10.8
You need to do two things:
pip install googletrans==3.1.0a0
Then:
from googletrans import Translator
def TranslationHintoEng(line):
return Translator(service_urls=['translate.googleapis.com']).translate(line, dest='en').text
print(TranslationHintoEng("कैसा है जारविस मेरी आवाज आ रही है"))
Output:
how are you jarvis my voice is coming
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.