Hallo, ich bin an einem Sprachassistenten dran und bin gerade bei der "Speech-to-Text" Funktion. Das ist mein bisheriger Code:
import speech_recognition as sr
def aufnahme():
r = sr.Recognizer()
with sr.Microphone() as quelle:
r.pause_threshold = 0.8
r.adjust_for_ambient_noise(quelle)
gesagt = r.listen(quelle)
try:
q = r.recognize_google(gesagt, language="de")
print("Recognized speech (Google):", q)
return q
except sr.UnknownValueError:
print('Leider nicht verstanden (Google)')
print("Recognized speech (Google):", r.recognize_google(gesagt, show_all=True, language="de"))
except sr.RequestError as e:
print(f'Fehler bei Sphinx-Erkennung: {e}')
return "Ich warte auf Anweisungen"
# Call the function
result = aufnahme()
print(result)
Jedoch funktioniert er richtig schlecht, er versteht höchstens zwei Wörter und in 90% der Fälle kommt dieser Fehlercode:
Leider nicht verstanden (Google)
Traceback (most recent call last):
File "C:\Users\...\PycharmProjects\voiceAssistant\main.py", line 21, in aufnahme
q = r.recognize_google(gesagt, language="de")
File "C:\Users\...\lib\site-packages\speech_recognition\recognizers\google.py", line 251, in recognize_legacy
return output_parser.parse(response_text)
File "C:\Users\...\lib\site-packages\speech_recognition\recognizers\google.py", line 124, in parse
actual_result = self.convert_to_result(response_text)
File "C:\Users\....\lib\site-packages\speech_recognition\recognizers\google.py", line 173, in convert_to_result
raise UnknownValueError()
speech_recognition.exceptions.UnknownValueError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\...\PycharmProjects\voiceAssistant\main.py", line 35, in <module>
result = aufnahme()
File "C:\Users\...\PycharmProjects\voiceAssistant\main.py", line 27, in aufnahme
print("Recognized speech (Google):", r.recognize_google(gesagt, show_all=True, language="de"))
File "C:\Users\...\lib\site-packages\speech_recognition\recognizers\google.py", line 251, in recognize_legacy
return output_parser.parse(response_text)
File "C:\Users\...\lib\site-packages\speech_recognition\recognizers\google.py", line 124, in parse
actual_result = self.convert_to_result(response_text)
File "C:\Users\...\lib\site-packages\speech_recognition\recognizers\google.py", line 173, in convert_to_result
raise UnknownValueError()
speech_recognition.exceptions.UnknownValueError
Process finished with exit code 1
Woran liegt das, soll ich eine andere Speech Recognition verwenden und wenn ja welche?
Vielen Dank im Voraus!