Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
263 views
in Technique[技术] by (71.8m points)

python - Voice-Translator code doesn't work - not sure why

Took the code from https://github.com/Arbazkhan4712/Voice-Translator/blob/master/trans.py changed it for myself ( changed the language to Russian ) what to do does not work, tried without changes also does not work My modified code

from googletrans import Translator
import pyttsx3
import speech_recognition as sr

engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices') 
engine.setProperty('voice',voices[1].id)

def speak(audio):
    engine.say(audio)
    engine.runAndWait()

def takeCommand():

    r = sr.Recognizer()
    with sr.Microphone() as source:
        print("Слушаю...")
        r.pause_threshold = 1
        audio = r.listen(source)

    try:
        print("Слушаю...")
        query = r.recognize_google(audio, language='ru-en')
        print(f"Вы:{query}
")

    except Exception as e:
        print(e)
        print("Скижите еще раз...")
        speak("Скижите еще раз...")
        return "None"
    return query

def Translate():
    speak("Что будем переводить??")
    sentence = takeCommand()
    trans = Translator()
    trans_sen = trans.translate(sentence,src='en',dest='ca')        
    print(trans_sen.text)
    speak(trans_sen.text)

Translate()

in the visual studio writes Message = The 'nonetype' object does not have the' Group 'attribute Source = C:Usersplzbasource eposмодуль1.py Stack Trace: File "C:Usersplzbasource eposмодуль1.py", line 41, in Translate()

in the cmd writes

Traceback (most recent call last): File "C:Usersplzbasource eposмодуль1.py", line 41, in Translate() File "C:Usersplzbasource eposмодуль1.py", line 37, in Translate trans_sen = trans.translate(sentence,src='en',dest='ca') File "C:UsersplzbaAppDataLocalProgramsPythonPython39libsite-packagesgoogletransclient.py", line 182, in translate data = self._translate(text, dest, src, kwargs) File "C:UsersplzbaAppDataLocalProgramsPythonPython39libsite-packagesgoogletransclient.py", line 78, in _translate token = self.token_acquirer.do(text) File "C:UsersplzbaAppDataLocalProgramsPythonPython39libsite-packagesgoogletransgtoken.py", line 194, in do self._update() File "C:UsersplzbaAppDataLocalProgramsPythonPython39libsite-packagesgoogletransgtoken.py", line 62, in _update code = self.RE_TKK.search(r.text).group(1).replace('var ', '') AttributeError: 'NoneType' object has no attribute 'group'


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...