Spaces:
Runtime error
Runtime error
File size: 2,010 Bytes
dd2fd57 83c0605 16d67e4 38591a9 dd2fd57 83c0605 dd2fd57 16d67e4 dd2fd57 16d67e4 dd2fd57 16d67e4 83c0605 dd2fd57 83c0605 dd2fd57 |
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 39 40 41 42 43 44 45 46 47 48 49 50 51 |
import os
import gradio as gr
from pyannote.audio import Pipeline
from faster_whisper import WhisperModel
# ืืชืงื ื ืฉื PyAnnote ืืืืื ืืขืืืื ืื ืืืชืงื
os.system('pip install pyannote.audio')
# ืืขืื ืช ื-Pipeline ืฉื PyAnnote ืืืืืจืืืฆืื
pipeline = Pipeline.from_pretrained("pyannote/speaker-diarization")
# ืืขืื ืช ืืืืื ืฉื Whisper ืืชืืืื
whisper_model = WhisperModel("openai/whisper-large", device="cuda")
# ืคืื ืงืฆืื ืฉืืืฆืขืช ืืืืจืืืฆืื ืืชืืืื
def diarize_and_transcribe(audio_file):
# ืฉืื 1: ืืืืจืืืฆืื
diarization = pipeline(audio_file)
# ืืฉืชื ื ืืฉืืืจ ืืช ืืชืืืื ืืืืื ืขื ืืืืข ืขื ืืืืืจืื
full_transcription = []
# ืืขืืจ ืขื ืื ืืืงืืขืื ืฉื ืืฆืื ืขื ืืื ืืืืจืืืฆืื
for segment, _, speaker in diarization.itertracks(yield_label=True):
# ืืืจืช ืืงืืข ืืืื ืืคืืจืื ืืชืืื ืืชืืืื
start_time = segment.start
end_time = segment.end
# ืชืืืื ืืืงืืข ืืขืืจืช Whisper
segments, _ = whisper_model.transcribe(audio_file, language="he", task="transcribe",
segment_start=start_time, segment_end=end_time)
transcription = " ".join([seg.text for seg in segments])
# ืืืกืคืช ืชืืฆืื ืืชืืืื ืืืืื
full_transcription.append(f"Speaker {speaker}: {transcription} (from {start_time:.2f} to {end_time:.2f})")
# ืืืืจืช ืืชืืืื ืืืื ืขื ืืืืงื ืืืืืจืื
return "\n".join(full_transcription)
# ืืฆืืจืช ืืืฉืง ืืจืืื
interface = gr.Interface(
fn=diarize_and_transcribe,
inputs=gr.Audio(source="upload", type="filepath"),
outputs="text",
title="Speaker Diarization and Transcription",
description="Upload an audio file to perform both speaker diarization and transcription."
)
# ืืจืฆืช ืืืคืืืงืฆืื
interface.launch()
|