Модуль Python «speech_recognition» не имеет «распознавания»?Python

Программы на Python
Ответить
Anonymous
 Модуль Python «speech_recognition» не имеет «распознавания»?

Сообщение Anonymous »

Я пробовал какой-то код, который смотрел на видео, но когда мне пришлось запустить программу, она выдала следующий текст: «Произошла ошибка: у модуля 'speech_recognition' нет атрибута 'recognite'». Я использовал Python
Это мой код:

Код: Выделить всё

import openai

import pyttsx3
import speech_recognition as sr
print ("TEST")
import time

# Initialize OpenAI API
openai.api_key = "myapikey"
# Initialize the text to speech engine
engine=pyttsx3.init()

def transcribe_audio_to_test(filename):
recogizer=sr.Recognizer()
with sr.AudioFile(filename)as source:
audio=recogizer.record(source)
try:
return recogizer.recognize_google(audio)
except:
print("skipping unkown error")

def generate_response(prompt):
response= openai.completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=4000,
n=1,
stop=None,
temperature=0.5,
)
return response ["Choices"][0]["text"]
def speak_text(text):
engine.say(text)
engine.runAndWait()

def main():
while True:
#Waith for user say "genius"
print("Say 'Genius' to start recording your question")
with sr.Microphone() as source:
recognizer=sr.Recognizer()
audio=recognizer.listen(source)
try:
transcription = recognizer.recognize_google(audio)
if transcription.lower()=="genius":
#record audio
filename ="input.wav"
print("Say your question")
with sr.Microphone() as source:
recognizer=sr.recognize()
source.pause_threshold=1
audio=recognizer.listen(source,phrase_time_limit=None,timeout=None)
with open(filename,"wb")as f:
f.write(audio.get_wav_data())

#transcript audio to test
text=transcribe_audio_to_test(filename)
if text:
print(f"yuo said {text}")

#Generate the response
response = generate_response(text)
print(f"chat gpt 3 say {response}")

#read resopnse using GPT3
speak_text(response)
except Exception as e:

print("An error ocurred : {}".format(e))
if __name__=="__main__":
main()
Я нажал «Выполнить» в Visual Studio, начал отладку и выбрал Python, но когда я попытался произнести выбранное мной слово, появилось сообщение об ошибке «Произошла ошибка: модуль «speech_recognition» не имеет атрибута «распознавать»»

Подробнее здесь: https://stackoverflow.com/questions/759 ... -recognize
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Python»