1

I've been trying to use OpenAI's whisper to transcribe some text.

Whenever I run, I get a FileNotFounderror.

My code is as follows:

import whisper
import os

print(os.listdir())

# f = open('test_text.txt', 'r')
# content = f. read()
# print(content)
# f. close()

audio = 'Users/geoff/Downloads/micro-machines.wav'
model = whisper.load_model("tiny")
result = model.transcribe('micro-machines.wav', fp16=False)
print(result['text'])

The commented out part with the opening of the text file was done as a test and runs each time without issue.

When the code prints the directory, I get the following correct list of files, But then the error follows immediarely after:

['.idea', 'main.py', 'micro-machines.wav', 'test_text.txt', 'venv']
Traceback (most recent call last):
  File "C:\Users\geoff\PycharmProjects\pythonProject3\main.py", line 16, in <module>
    result = model.transcribe('micro-machines.wav', fp16=False)
  File "C:\Users\geoff\PycharmProjects\pythonProject3\venv\lib\site-packages\whisper\transcribe.py", line 82, in transcribe
    mel = log_mel_spectrogram(audio)
  File "C:\Users\geoff\PycharmProjects\pythonProject3\venv\lib\site-packages\whisper\audio.py", line 111, in log_mel_spectrogram
    audio = load_audio(audio)
  File "C:\Users\geoff\PycharmProjects\pythonProject3\venv\lib\site-packages\whisper\audio.py", line 42, in load_audio
    ffmpeg.input(file, threads=0)
  File "C:\Users\geoff\PycharmProjects\pythonProject3\venv\lib\site-packages\ffmpeg\_run.py", line 313, in run
    process = run_async(
  File "C:\Users\geoff\PycharmProjects\pythonProject3\venv\lib\site-packages\ffmpeg\_run.py", line 284, in run_async
    return subprocess.Popen(
  File "C:\Users\geoff\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 966, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\geoff\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 1435, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified
coolsong
  • 11
  • 2

2 Answers2

0

There seems to be a mismatch in the file paths you've used for the commented part as observed from the output:

C:\Users\geoff\ PycharmProjects \ pythonProject3

and the following part.

audio = 'Users/geoff/Downloads/micro-machines.wav'

You may verify where the .wav file exists - in 'Downloads' or in 'pythonProject3' folder and try again.

Dhanashree
  • 21
  • 3
  • Thank you @Dhsnashree for picking up that mistake. I was testing across different directories to see if that was the source of my problem. I've now updated the code to read: `audio = 'Users/geoff/PycharmProjects/pythonProject3/micro-machines.wav' model = whisper.load_model("tiny") result = model.transcribe(audio, fp16=False) print(result['text'])` But still getting the same error. (I'm sorry for the poor formatting. I can't work out how to start a new line in these comments. – coolsong Sep 25 '22 at 21:45
  • Could you post the error message here? – Dhanashree Sep 26 '22 at 13:59
0

I had the same issue. It looks like the problem is in ffmpeg.

I tried to remove the ffmpeg package and install the ffmpeg-python package in pip (according to some advice) but that didn't help.

Finally I found this answer https://stackoverflow.com/a/65860115/9931930

It helped me. I just put ffmpeg.exe in the same folder as my script and it worked.

Elmir
  • 110
  • 11