fromSitePoint Forums | Web Development & Design Community
5 days agoDeveloping speech to text transcription on python
import whisper
import torch
import sys
def transcribe_audio(audio_path, language='el'):
""" Transcribes the given audio file to text in the specified language using Whisper.
Args: audio_path (str): Path to the audio file. language (str): Language code for transcription (default is 'el' for Greek).
Returns: str: The transcribed text. """
device = 'cuda' if torch.cuda.is_available() else 'cpu'
print(f'Using device: {device}')
model = whisper.load_model('small', device=device)
print(f'Transcribing {audio_path} in language: {language}...')
result = model.transcribe(audio_path, language=language, task='transcribe')
return result['text']