Spaces:
Build error
Build error
File size: 1,055 Bytes
d483661 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
import whisper
import os
import librosa
import torch
from transformers import pipeline
def transcribe_audio_raw(file_path: str) -> str:
# file_path = "C:/Users/Lenovo/ML Notebooks/ERP Assistant/example.wav"
# if not os.path.exists(file_path):
# print(f"File not found: {file_path}")
# else:
# print("File found!")
# audio_data, sr = librosa.load(file_path, sr=None)
whisper_pipe = pipeline("automatic-speech-recognition", model="openai/whisper-tiny.en", device="cpu")
transcription = whisper_pipe(file_path)
print(transcription)
return transcription['text']
import tempfile
def transcribe_audio(uploaded_file):
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as temp_file:
temp_file.write(uploaded_file.read())
file_path = temp_file.name
whisper_pipe = pipeline("automatic-speech-recognition", model="openai/whisper-tiny.en", device="cpu")
transcription = whisper_pipe(file_path)
return transcription['text']
|