Startonix / Modular-AI

Advanced AI Training and Building Repository
0 stars 0 forks source link

Speech Recognition Integration #127

Open Startonix opened 1 month ago

Startonix commented 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

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))