A union of curiosity and data science

Knowledgebase and brain dump of a database engineer

Google Translate API - Wav file speech recognition with python3

This api transcribes up to 1 min of audio to text. You'll need a google cloud account. 


#!/usr/bin/env python3

import speech_recognition as sr
from os import path

audio = "K:\\random\\part4.wav"
r = sr.Recognizer() #recognizer object, we can use various services with this including  google, microsoft and ibm watson
with sr.AudioFile(audio) as source:
    audio = r.record(source)  # read the entire audio file

# Google Cloud Speech Recognition
Whisper = r"""<entire contents of json credentials from google>"""
    ish =  r.recognize_google_cloud(audio, credentials_json=Whisper)
    print("Transcribed:...  " +ish)
    file = open("K:\\random\\part4.txt","w")
except sr.RequestError as e:
    print("Sorry, can't help you. ; {0}".format(e))
except sr.UnknownValueError:
    print("What was that?")


Comments (1) -

  • pamelaboswell

    11/13/2019 6:19:52 AM | Reply

    This article aims to provide an introduction on how to make use of the SpeechRecognition library of Python. This is useful as it can be used on microcontrollers such as Raspberri Pis with the help of an external microphone.

Add comment