U
U
uzi_no_uzi2022-02-16 14:20:59
Python
uzi_no_uzi, 2022-02-16 14:20:59

How to quickly recognize speech from an audio file?

There is a link with an audio file in mp3 format. At the moment, this functionality is implemented in the following way:

link = driver.find_element(By.XPATH, '/html/body/div/div/div[7]/a').get_attribute('href');
    myfile = requests.get(link)
    open('C:/Users/user/Desktop/unbot/audio.mp3', 'wb').write(myfile.content)
    sound = AudioSegment.from_mp3("audio.mp3")
    sound.export("file.wav", format="wav")




    from os import path
    AUDIO_FILE = path.join(path.dirname(path.realpath(__file__)), "file.wav")

    r = sr.Recognizer()
    with sr.AudioFile(AUDIO_FILE) as source:
        audio = r.record(source)

    try:
        print("Google Speech Recognition thinks you said " + r.recognize_google(audio))
    except sr.UnknownValueError:
        print("Google Speech Recognition could not understand audio")
    except sr.RequestError as e:
        print("Could not request results from Google Speech Recognition service; {0}".format(e))


Those. we download a file from the link, convert it to wav, recognize speech and get the result. This is done through Google Speech Recognition. All this takes about 3-4 seconds in total, but it's too long for my task. Is there any way to speed up the process? There is no option not to convert to wav, because the speech_recognition library does not work in mp3 format. I also heard about some Google API, paid, maybe someone used it, if you try through it, will it be faster?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nikolay Savelyev, 2022-02-16
@AgentSmith

If you want faster - make your own recognizer.
No one will give you this Klondike for free

A
Anton Popov, 2022-02-16
@ademaro

I use offline speech recognition using the vosk library: https://github.com/alphacep/vosk-api
I think it will be much faster)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question