Ngoufack commited on
Commit
238e4c8
·
1 Parent(s): e0dc9fc

hotfix 3.0

Browse files
Files changed (1) hide show
  1. app.py +13 -4
app.py CHANGED
@@ -31,8 +31,15 @@ def transcribe(inputs, task):
31
  if inputs is None:
32
  raise gr.Error("No audio file submitted! Please upload or record an audio file before submitting your request.")
33
 
 
 
 
 
 
34
  segments, _ = model.transcribe(inputs, task=task)
35
- text = " ".join([segment.text for segment in segments])
 
 
36
  diarization = pipeline(inputs)
37
  speaker_segments = []
38
  for segment, _, speaker in diarization.itertracks(yield_label=True):
@@ -40,9 +47,11 @@ def transcribe(inputs, task):
40
 
41
  # Associer les segments de transcription aux locuteurs
42
  speaker_texts = []
43
- #diarization = pipeline({"uri": "audio", "audio": audio_path})
44
- #speaker_segments = []
45
- return text
 
 
46
 
47
  def _return_yt_html_embed(yt_url):
48
  video_id = yt_url.split("?v=")[-1]
 
31
  if inputs is None:
32
  raise gr.Error("No audio file submitted! Please upload or record an audio file before submitting your request.")
33
 
34
+ waveform, sample_rate = torchaudio.load(inputs)
35
+ if sample_rate != 16000:
36
+ transform = torchaudio.transforms.Resample(orig_freq=sample_rate, new_freq=16000)
37
+ waveform = transform(waveform)
38
+
39
  segments, _ = model.transcribe(inputs, task=task)
40
+ transcription = "\n".join([segment.text for segment in segments])
41
+
42
+ # Diarisation avec le pipeline de pyannote
43
  diarization = pipeline(inputs)
44
  speaker_segments = []
45
  for segment, _, speaker in diarization.itertracks(yield_label=True):
 
47
 
48
  # Associer les segments de transcription aux locuteurs
49
  speaker_texts = []
50
+ for start, end, speaker in speaker_segments:
51
+ spoken_text = " ".join([seg.text for seg in segments if seg.start >= start and seg.end <= end])
52
+ if spoken_text:
53
+ speaker_texts.append(f"{speaker}: {spoken_text}")
54
+ return "\n".join(speaker_texts)
55
 
56
  def _return_yt_html_embed(yt_url):
57
  video_id = yt_url.split("?v=")[-1]