0

I'm trying to get this reCaptcha code to run and I've gotten very close but I get this error:

  File "search_bot.py", line 53, in solveReCaptcha
    sound = pydub.AudioSegment.from_mp3(os.getcwd()+"\\sample.mp3")
  File "C:\Users\username\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pydub\audio_segment.py", line 738, in from_mp3
    return cls.from_file(file, 'mp3', parameters=parameters)
  File "C:\Users\username\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pydub\audio_segment.py", line 685, in from_file
    info = mediainfo_json(orig_file, read_ahead_limit=read_ahead_limit)
  File "C:\Users\username\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pydub\utils.py", line 274, in mediainfo_json
    res = Popen(command, stdin=stdin_parameter, stdout=PIPE, stderr=PIPE)
  File "C:\Users\username\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 709, in __init__
    restore_signals, start_new_session)
  File "C:\Users\username\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 997, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

It's throwing an error on a .py file that I didn't even write but is just part of the Python lib so I don't know how to fix it or even why I am getting it. I already looked at this answer but it didn't help me.

EDIT:

This the code that is throwing the error:

urllib.request.urlretrieve(src, os.getcwd() + "\\sample.mp3")
sound = pydub.AudioSegment.from_mp3(os.getcwd() + "\\sample.mp3")
sound.export(os.getcwd() + "\\sample.wav", format="wav")
sample_audio = sr.AudioFile(os.getcwd() + "\\sample.wav")
r = sr.Recognizer()
Salah Assana
  • 186
  • 4

1 Answers1

0

the error message points to sample.np3 not being found in the directory from which you executed the scritp. you can try replacing the path for os.path.join(os.path.dirname(__file__), 'sample.mp3')

  • The file sample.mp3 is in the same directory as the .py file. `os.getcwd() + "\\sample.mp3"` is how I added the file in the first place so it should work for reading it. I've added the code so you can see how it works. – Salah Assana Nov 08 '20 at 02:48
  • Try using `os.path.join` instead of using `+` to join path names. Python will build the path for you without having to worry about compatibility issues. – Martin Castro Alvarez Nov 09 '20 at 20:10