DEV Community

Cover image for Transcribing Audio in Python
Israel-Lopes
Israel-Lopes

Posted on

Transcribing Audio in Python

Dependencies

  • build-essential
  • portaudio19-dev
  • pyaudio
  1. sudo apt-get install build-essential
  2. sudo apt install portaudio19-dev
  3. pip install pyaudio

Example


import speech_recognition as sr

r = sr.Recognizer()

while True:
    # Initialize the microphone
    with sr.Microphone() as source:
        print("Speak!!: ")
        audio = r.listen(source)

    try:
        # do the transcription
        transcription = r.recognize_google(audio, language='en-US')
        print(transcription)

    except sr.UnknownValueError:
        print("Didn't understand the audio")

    except sr.RequestError:
        print("request error")

Enter fullscreen mode Exit fullscreen mode

Texto alternativo da imagem)

Top comments (0)