1

Hace algún tiempo hice un programa para un asistente de voz en Python, he cambiado el PC e instalado todas las librerías, pero por algún motivo, cuando trato de ejecutarlo me devuelve el error:

PS K:\programación\Python\PC IA\Bernat>  & 'C:\Program Files\Python38\python.exe' 'c:\Users\Inderlard\.vscode\extensions\ms-python.python-2021.8.1159798656\pythonFiles\lib\python\debugpy\launcher' '49997' '--' 'k:\programación\Python\PC IA\Bernat\Asistente.py' 
    C:\Users\Inderlard\AppData\Roaming\Python\Python38\site-packages\pydub\utils.py:170: RuntimeWarning: Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work
      warn("Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work", RuntimeWarning)
    Traceback (most recent call last):
      File "k:\programación\Python\PC IA\Bernat\Asistente.py", line 14, in <module>  
        from reconogizer import recon
      File "k:\programación\Python\PC IA\Bernat\reconogizer.py", line 20, in <module>
        FORMAT = pyaudio.paInt16
    NameError: name 'pyaudio' is not defined

El problema me lo marca en la linea 20.

    # Lybraries:
    import os
    import time
    import wave
    from array import array
    from struct import pack
    from sys import byteorder
    #import numpy as np
    #import pyaudio
    import speech_recognition as sr
    import win32serviceutil
    from matplotlib import pylab
    from pydub import AudioSegment
    
    
    # Program variables:
    THRESHOLD = 500 
    CHUNK_SIZE = 1024
    CHUNK_SIZE_PLAY = 1024
    FORMAT = pyaudio.paInt16 # Aquí esta el fallo
    RATE = 44100
    MAXIMUM = 16384

1 respuesta 1

1

Explicación NameError

El error es claro: NameError: name 'pyaudio' is not defined, se puede replicar de la siguiente forma

variable_1 = 1
print(variable_2)

Salida: NameError: name 'variable_2' is not defined.

El error te está diciendo, "Estas llamando a una variable que no está definida, es decir, que no existe". Al no existir no se puede utilizar.

Tu problema

Entendiendo la base del error que es que pyaudio no existe, ahora hay que averiguar porque no existe.

En Python la almoadilla # se utiliza para comentar el código y la linea en la que ejecutas import pyaudio está comentada, cuando una linea está comentada, Python al compilar y ejecutar no la procesa. Deberías quedarla así: import pyaudio

1
  • Vale... Ahora se me cae la cara de verguenza jajajaja, he revisado el codigo un monton de veces y no me he dado cuenta de algo tan tonto, jajaja, perdona y mil gracias
    – inderlard
    el 1 sep. 2021 a las 18:08

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.