Python: Convert Speech to Text Using SpeechRecognition

In this tutorial, we will introduce how to convert a audio to text using python SpeechRecognition library.

Python: Convert Speech to Text Using SpeechRecognition

1.Install SpeechRecognition and pydub

pip install SpeechRecognition pydub

2.Import library

import speech_recognition as sr

3.Reading a file

filename = "16-122828-0002.wav"

4.Initialize the recognizer

r = sr.Recognizer()

5.Start to convert speech to text

with sr.AudioFile(filename) as source:
    # listen for the data (load audio to memory)
    audio_data = r.record(source)
    # recognize (convert from speech to text)
    text = r.recognize_google(audio_data)
    print(text)

Run this code, you may see this text:

I believe you're just talking nonsense