Open Startonix opened 1 month ago
speech_recognition.py
from google.cloud import speech_v1 as speech import io
def transcribe_speech(audio_file_path): client = speech.SpeechClient() with io.open(audio_file_path, "rb") as audio_file: content = audio_file.read()
audio = speech.RecognitionAudio(content=content) config = speech.RecognitionConfig( encoding=speech.RecognitionConfig.AudioEncoding.LINEAR16, sample_rate_hertz=16000, language_code="en-US", ) response = client.recognize(config=config, audio=audio) return response
audio_file_path = 'path/to/audio.wav' response = transcribe_speech(audio_file_path) for result in response.results: print("Transcript: {}".format(result.alternatives[0].transcript))
speech_recognition.py
from google.cloud import speech_v1 as speech import io
def transcribe_speech(audio_file_path): client = speech.SpeechClient() with io.open(audio_file_path, "rb") as audio_file: content = audio_file.read()
Example usage
audio_file_path = 'path/to/audio.wav' response = transcribe_speech(audio_file_path) for result in response.results: print("Transcript: {}".format(result.alternatives[0].transcript))