0

I'm trying to use the speech recognition library to set up a voice assistant, but I keep receiving a permission denied error. I suppose that the error is that the file isn't saved at any location where Python can access it, but I'm not entirely sure how to change the directory where the file is stored using this library.

Code:

import speech_recognition as sr

r = sr.Recognizer()

with sr.Microphone() as source:
            print("Say something!")
            try:
                audio = r.listen(source, timeout=5) 
            except sr.WaitTimeoutError:
                print("You didn't say anything")

            print("Did you say " + r.recognize_whisper(audio))

Traceback:

Traceback (most recent call last):
  File "C:\Users\s\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\whisper\audio.py", line 42, in load_audio
    ffmpeg.input(file, threads=0)
  File "C:\Users\s\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\ffmpeg\_run.py", line 325, in run
    raise Error('ffmpeg', out, err)
ffmpeg._run.Error: ffmpeg error (see stderr output for detail)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "c:\Users\s\projects\FinalProject\debugging.py", line 12, in <module>
    print("Did you say " + r.recognize_whisper(audio))
  libswresample   4.  9.100 /  4.  9.100  libpostproc    56.  7.100 / 56.  7.100
C:\Users\s\AppData\Local\Temp\tmpt5niak28.wav: Permission denied

I've used this library before successfully, so not sure what the issue is. Any suggestions?

Nick ODell
  • 15,465
  • 3
  • 32
  • 66

1 Answers1

0

I can tell from the error being thrown that you are using Windows. I have some clarifying questions (which I can't present well in the comments):

What I think is happening here matches your own assumptions:

  • The speech_recognition module, when r.listen is called, creates a binary stream, as shown on this line of the speech_recognition source code.

  • This method does not seem to provide an interface at all to change where the stream is stored, so I think it is saving it to some sort of default location, which for Windows, appears to be Temp - I don't know a lot about Python on Windows, so this is an assumption.

To think of ways to resolve the problem:

  • I would try to create a Virtual Environment, which may change the default location in which the microphone stream, and resulting WAV file, is stored. A venv's job is to isolate the execution of Python code from the wider system, so I would expect it not to store in Temp if it were in a Virtual Environment.
Kathy Reid
  • 575
  • 4
  • 6
  • 1
    Thank you for your reply! * I'm on Windows 11, version 21H2 * I'm using VSCode, if that answers the question * I installed PyAudio using pip install in my VSCode program. I just tried setting up a virtual environment inside VSCode, installing the required packages and running the file in there to see if this would resolve the issue, I'm however left with another error message tracing back to the __init__ method in the whisper package. I resolved everything by using r.reconize_google() instead of whisper, which worked. Thanks! – sally carlund Jan 30 '23 at 16:49