Turriano
Posts: 6
Joined: Fri Feb 10, 2017 4:20 pm

Dictar por voz en Raspberry con Python

Sat Jan 28, 2023 4:21 pm

Llevo intentando desde hace tiempo, hacer un programa en Python, que me reconozca palabras y las meta en una cadena de texto.
Pruebe lo que pruebe, no me funciona.
A pesar de que he cargado todas las librerías necesarias.
Incluso le he preguntado a ChatGPT y me ha dado este programa, que tampoco funciona:

import speech_recognition as sr

# Inicializamos el reconocedor de voz
r = sr.Recognizer()

# Escuchamos al micrófono con el reconocedor
with sr.Microphone() as source:
print("Di algo: ")
audio = r.listen(source)

# Intentamos reconocer lo que se ha dicho usando el reconocedor integrado
try:
text = r.recognize_sphinx(audio)
print(f"Has dicho: {text}")
except sr.UnknownValueError:
print("No se ha podido reconocer lo que has dicho")
except sr.RequestError as e:
print("Error al llamar al servicio de reconocimiento de voz")


Thonny, me dice esto:
Python 3.7.3 (/usr/bin/python3)
>>> %Run Audio.py
Traceback (most recent call last):
File "/home/pi/.local/lib/python3.7/site-packages/speech_recognition/__init__.py", line 120, in get_pyaudio
import pyaudio
ModuleNotFoundError: No module named 'pyaudio'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/pi/Desktop/Prog/PyDictado/Audio.py", line 10, in <module>
mic = sr.Microphone(device_index=1)
File "/home/pi/.local/lib/python3.7/site-packages/speech_recognition/__init__.py", line 92, in __init__
self.pyaudio_module = self.get_pyaudio()
File "/home/pi/.local/lib/python3.7/site-packages/speech_recognition/__init__.py", line 122, in get_pyaudio
raise AttributeError("Could not find PyAudio; check installation")
AttributeError: Could not find PyAudio; check installation
>>> %cd /home/pi/Desktop/Prog/PyDictado/ProgsIA
>>> %Run Prog2VOZ.py
Error al llamar al servicio de reconocimiento de voz
>>> %Run Prog1Voz.py
Traceback (most recent call last):
File "/home/pi/.local/lib/python3.7/site-packages/speech_recognition/__init__.py", line 120, in get_pyaudio
import pyaudio
ModuleNotFoundError: No module named 'pyaudio'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/pi/Desktop/Prog/PyDictado/ProgsIA/Prog1Voz.py", line 7, in <module>
with sr.Microphone() as source:
File "/home/pi/.local/lib/python3.7/site-packages/speech_recognition/__init__.py", line 92, in __init__
self.pyaudio_module = self.get_pyaudio()
File "/home/pi/.local/lib/python3.7/site-packages/speech_recognition/__init__.py", line 122, in get_pyaudio
raise AttributeError("Could not find PyAudio; check installation")
AttributeError: Could not find PyAudio; check installation
>>>

Yuna ventana aparte, que dice:
"Problem When handling 'ToplevelResponse'
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/thonny/workbench.py", line 1598, in event_generate
handler(event)
File "/usr/lib/python3/dist-packages/thonny/assistance.py", line 132, in handle_toplevel_response
self._explain_exception(msg["user_exception"])
File "/usr/lib/python3/dist-packages/thonny/assistance.py", line 171, in _explain_exception
_error_helper_classes.get(error_info["type_name"], []) + _error_helper_classes["*"]
File "/usr/lib/python3/dist-packages/thonny/assistance.py", line 170, in <listcomp>
for helper_class in (
File "/usr/lib/python3/dist-packages/thonny/plugins/stdlib_error_helpers.py", line 465, in __init__
assert len(names) == 2
AssertionError

¿Me podríais ayudar? :cry:

Return to “Español”