pyscript icon indicating copy to clipboard operation
pyscript copied to clipboard

Exception in <file.stt.status> line 8: with sr.AudioFile(filename) as source: ^ AttributeError: 'NoneType' object has no attribute 'close'

Open backslashV opened this issue 3 years ago • 1 comments

/config/pyscript/stt.py

import speech_recognition as sr

@service
def status(filename="audio.wav"):
  # initialize the recognizer
  r = sr.Recognizer()
  # open the file
  with sr.AudioFile(filename) as source:
    # listen for the data (load audio to memory)
    audio_data = r.record(source)
    # recognize (convert from speech to text)
    text = r.recognize_google(audio_data)
    log.info(text)

/config/pyscript/requirements.txt

SpeechRecognition
pydub

"audio.wav" is in /config/pyscript.

When I run the service, however, I get

Exception in <file.stt.status> line 8: with sr.AudioFile(filename) as source: ^ AttributeError: 'NoneType' object has no attribute 'close'

backslashV avatar Jun 28 '21 02:06 backslashV

my guess is that the filename you are providing can't be found. I think python is running in the config directory so your file would need to be there, not in the pyscript folder, or your path would need to be pyscript/audio.wav

raman325 avatar Jul 07 '21 06:07 raman325

@backslashV could you please update or close the issue? Thank you

ALERTua avatar Sep 21 '23 09:09 ALERTua