CoolFace
Modelpublic

hackergeek98/whisper-persian-turbooo

sourceHugging Facemitupdated 2y agoView on Hugging Face
3likes15downloads
Model Card

training loss: 0.013100 validation loss: 0.043175 num. epoch: 1

how to use the model in colab:

# Install required packages !pip install torch torchaudio transformers pydub google-colab

import torch from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline from pydub import AudioSegment import os from google.colab import files

# Load the model and processor modelid = "hackergeek98/whisper-persian-turbooo" device = "cuda" if torch.cuda.isavailable() else "cpu"

model = AutoModelForSpeechSeq2Seq.frompretrained(modelid).to(device) processor = AutoProcessor.frompretrained(modelid)

# Create pipeline whisperpipe = pipeline( "automatic-speech-recognition", model=model, tokenizer=processor.tokenizer, featureextractor=processor.featureextractor, device=0 if torch.cuda.isavailable() else -1 )

# Convert audio to WAV format def converttowav(audiopath): audio = AudioSegment.fromfile(audiopath) wavpath = "convertedaudio.wav" audio.export(wavpath, format="wav") return wav_path

# Split long audio into chunks def splitaudio(audiopath, chunklengthms=30000): # Default: 30 sec per chunk audio = AudioSegment.fromwav(audiopath) chunks = [audio[i:i+chunklengthms] for i in range(0, len(audio), chunklengthms)] chunk_paths = []

for i, chunk in enumerate(chunks): chunkpath = f"chunk{i}.wav" chunk.export(chunkpath, format="wav") chunkpaths.append(chunk_path)

return chunk_paths

# Transcribe a long audio file def transcribelongaudio(audiopath): wavpath = converttowav(audiopath) chunkpaths = splitaudio(wavpath) transcription = ""

for chunk in chunkpaths: result = whisperpipe(chunk) transcription += result["text"] + "\n" os.remove(chunk) # Remove processed chunk

os.remove(wav_path) # Cleanup original file

# Save transcription to a text file textpath = "transcription.txt" with open(textpath, "w") as f: f.write(transcription)

return text_path

# Upload and process audio in Colab uploaded = files.upload() audiofile = list(uploaded.keys())[0] transcriptionfile = transcribelongaudio(audio_file)

# Download the transcription file files.download(transcription_file)