Convert audio to text using GCP Speech API
pip install --upgrade google-cloud-speech
#!/bin/bash
export GOOGLE_APPLICATION_CREDENTIALS=$(pwd)/credentials-file.json
python gcp.py
# gcp.py
import io, os, subprocess, json
from google.cloud import speech
from google.cloud.speech import enums
from google.cloud.speech import types
def transcribe_file(speech_file):
client = speech.SpeechClient()
with io.open(speech_file, 'rb') as audio_file:
content = audio_file.read()
audio = types.RecognitionAudio(content=content)
config = types.RecognitionConfig(
encoding = enums.RecognitionConfig.AudioEncoding.LINEAR16,
sample_rate_hertz = 16000,
language_code = 'en-GB'
# language_code = 'en-US'
)
response = client.recognize(config, audio)
return response