Исправьте код в Python ( голосовой переводчик)

Вроде ошибка в Translate

from googletrans import Translator
import pyttsx3
import speech_recognition as sr


translator = Translator(service_urls=[
      'translate.google.com',
      'translate.google.co.kr',
    ])
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}\n")

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


def Translate():
    if len(list(filter(lambda x: ord(x.lower()) in range(1072, 1104), sentence))):
    print('query is too short')
    return False
    sentence = takeCommand()
    while len(list(filter(lambda x: ord(x.lower()) in range(1072, 1104), sentence))) <= 0:
    print('query is too short')
    sentence = takeCommand()
    speak("Что будем переводить??")
    sentence = takeCommand()
    trans = Translator()
    trans_sen = trans.translate(sentence, src='ru', dest='en')
    print(trans_sen.text)
    speak(trans_sen.text)


Translate()

Ответы (0 шт):