Тима Иванов
Знаток
(285),
на голосовании
1 месяц назад
import speech_recognition as sr
def record_and_recognize_audio(): """ Запись и распознавание аудио """ with sr.Microphone() as source: print("Listening...") audio = sr.Recognizer().listen(source)
try: text = sr.Recognizer().recognize_google(audio, language="ru") print(f"You said: {text}") except sr.UnknownValueError: print("Sorry, I couldn't understand that.") except sr.RequestError: print("Sorry, there was an error processing your request.")
return text
if __name__ == "__main__": audio = record_and_recognize_audio() print(audio)
def record_and_recognize_audio():
"""
Запись и распознавание аудио
"""
with sr.Microphone() as source:
print("Listening...")
audio = sr.Recognizer().listen(source)
try:
text = sr.Recognizer().recognize_google(audio, language="ru")
print(f"You said: {text}")
except sr.UnknownValueError:
print("Sorry, I couldn't understand that.")
except sr.RequestError:
print("Sorry, there was an error processing your request.")
return text
if __name__ == "__main__":
audio = record_and_recognize_audio()
print(audio)