0

This Python script cannot find the specified file even though I have confirmed that the path is accurate. I've also tried referencing this same file with other scripts and did not run into this error. Any reason why this would happen?

Error:

FileNotFoundError: [WinError 2] The system cannot find the file specified
[Finished in 1.5s with exit code 1]

Error when intentionally breaking the file link:

FileNotFoundError: [Errno 2] No such file or directory: 
'C:\\Users\\[name]\\Desktop\\BREAKslide14.mp3'
import speech_recognition as sr
from os import path
from pydub import AudioSegment

AudioSegment.converter = r"C:\Users\[name]\Downloads\ffmpeg-20200603-b6d7c4c-win64-static\ffmpeg-20200603-b6d7c4c-win64-static\bin\ffmpeg.exe"


# convert mp3 file to wav
file = r"C:\Users\[name]\Desktop\slide14.mp3"                                                       
sound = AudioSegment.from_mp3(file)
sound.export("transcript.wav", format="wav")


# transcribe audio file                                                         
AUDIO_FILE = "transcript.wav"

# use the audio file as the audio source                                        
r = sr.Recognizer()
with sr.AudioFile(AUDIO_FILE) as source:
        audio = r.record(source)  # read the entire audio file                  

        print("Transcription: " + r.recognize_google(audio))
RCarmody
  • 712
  • 1
  • 12
  • 29

2 Answers2

1

The line where it errored would be useful, but try this when you assign the variable file:

name = "YourUsername"
file = f"C:\Users\{name}\Desktop\slide14.mp3"

Maybe Python tried looking for this directory: C:\Users[name]\Desktop\slide14.mp3

Krishnan Shankar
  • 780
  • 9
  • 29
  • No luck here... It fails on the sound = AudioSegment.from_mp3(file) line – RCarmody Jun 04 '20 at 13:15
  • Yes, but that might be because the file name is invalid when getting a from_mp3 file. Maybe just copy the exact file directory. – Krishnan Shankar Jun 05 '20 at 02:50
  • New information: When I adjust the file location to something wrong, it gives me a different error.... So I'd assume it is picking up the file but doesn't know how to handle it for some reason – RCarmody Jun 05 '20 at 17:00
  • Did you verify the original mp3 file (by playing it for example)? – Krishnan Shankar Jun 06 '20 at 17:45
  • I did - I actually just created it with a GTTS text-to-speech, tested it, and it's 100% working. I'm looking to test out this program as the result – RCarmody Jun 07 '20 at 15:20
  • This probably isn't going to work, but just give it a try. Sometimes, files are inaccessible in C: drive. Try moving the audio file to your D: drive instead. Again, this might not work, but just give it a try. – Krishnan Shankar Jun 08 '20 at 21:59
0

Short answer

You have to set AudioSegment.converter to the correct ffmpeg.exe file. In your current code you're setting it to a linux/mac directory. Find the correct directory where ffmpeg.exe is and set AudioSegment.converter the coreect variable.

Long answer

Download ffmpeg from this link then unzip it and put it in your desktop. after that change AudioSegment.cenverter value to something like this:

AudioSegment.converter = r"C:\Users\[name]\Desktop\ffmpeg-20200603-b6d7c4c-win64-static\bin\ffmpeg.exe"
Mathemagician
  • 431
  • 4
  • 13
  • I did this, but no luck :( New information: When I adjust the file location to something wrong, it gives me a different error.... So I'd assume it is picking up the file but doesn't know how to handle it for some reason – RCarmody Jun 05 '20 at 17:00
  • @RCarmody recheck your address, the address that you've put in your code is wrong. (You included ffmpeg-20200603-b6d7c4c-win64-static.zip in the address which you shouldn't) – Mathemagician Jun 05 '20 at 18:33
  • Copy/pasted from the file properties: C:\Users\[name]\Downloads\ffmpeg-20200603-b6d7c4c-win64-static\ffmpeg-20200603-b6d7c4c-win64-static\bin – RCarmody Jun 05 '20 at 19:23