Answer the question
In order to leave comments, you need to log in
Why can't find the path?
I have this code here:
import speech_recognition as sr
import pydub
def recognition(file_src, file_src2):
sound = pydub.AudioSegment.from_mp3(file_src)
sound.export(file_src2, format="wav")
sample_audio = sr.AudioFile(file_src2)
key = sr.recognize_google(sample_audio)
return key
print(recognition('audio5.mp3', 'test.wav'))
Traceback (most recent call last):
File "c:\Users\Дом\Desktop\Py\PY\e_garant_bot\audio_2_text.py", line 19, in <module>
print(recognition('captcha_audio5.mp3', 'test.wav'))
File "c:\Users\Дом\Desktop\Py\PY\e_garant_bot\audio_2_text.py", line 12, in recognition
sound = pydub.AudioSegment.from_mp3(file_src)
File "C:\Users\Дом\AppData\Local\Programs\Python\Python39\lib\site-packages\pydub\audio_segment.py", line 796, in from_mp3
return cls.from_file(file, 'mp3', parameters=parameters)
File "C:\Users\Дом\AppData\Local\Programs\Python\Python39\lib\site-packages\pydub\audio_segment.py", line 728, in from_file
info = mediainfo_json(orig_file, read_ahead_limit=read_ahead_limit)
File "C:\Users\Дом\AppData\Local\Programs\Python\Python39\lib\site-packages\pydub\utils.py", line 274, in mediainfo_json
res = Popen(command, stdin=stdin_parameter, stdout=PIPE, stderr=PIPE)
File "C:\Users\Дом\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 951, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\Дом\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 1420, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] Не удается найти указанный файл
Answer the question
In order to leave comments, you need to log in
Found the answer: https://progi.pro/kak-ispravit-filenotfounderror-w...
Code:
import speech_recognition as sr
from pydub import AudioSegment
import os, sys
from pathlib import Path
def recognition(file_src, file_src2):
AudioSegment.converter = f"{os.getcwd()}\\ffmpeg.exe"
AudioSegment.ffprobe = f"{os.getcwd()}\\ffprobe.exe"
file_src = Path(file_src)
file_src2 = Path(file_src2)
audio = AudioSegment.from_mp3(file_src)
audio.export(file_src2, format="wav")
r = sr.Recognizer()
with sr.AudioFile(open(file_src2, 'rb')) as source:
audio = r.record(source) # read the entire audio file
return r.recognize_google(audio)
print(recognition('captcha_audio5.mp3', 'test.wav'))
I would advise you to start by moving the code to a folder in the root of the C drive without Russian letters in the path.
Well, after that, I would just try to open it through with open(src_file, “rb”) - will it open?
(By the way, for working with file paths, I recommend pathlib2, a very handy thing. There is a check for the presence of files and folders, and concatenation through /, all that).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question