salmanmapkar commited on
Commit
1bdf16c
1 Parent(s): 569a0c7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -0
app.py CHANGED
@@ -11,6 +11,13 @@ import gradio as gr
11
  import traceback
12
  import json
13
  pipeline = Pipeline.from_pretrained("pyannote/speaker-diarization", use_auth_token="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")
 
 
 
 
 
 
 
14
  __FILES = set()
15
 
16
  def CreateFile(filename):
@@ -113,6 +120,7 @@ def AudioTranscribe(NumberOfSpeakers=None, SpeakerNames="", audio="", retries=5)
113
  return AudioTranscribe(audio, retries-1)
114
  if not (os.path.isfile("temp_audio.wav")):
115
  return AudioTranscribe(audio, retries-1)
 
116
  return Transcribe()
117
  else:
118
  raise gr.Error("There is some issue ith Audio Transcriber. Please try again later!")
@@ -127,6 +135,7 @@ def VideoTranscribe(NumberOfSpeakers=None, SpeakerNames="", video="", retries=5)
127
  return VideoTranscribe(video, retries-1)
128
  if not (os.path.isfile("temp_audio.wav")):
129
  return VideoTranscribe(video, retries-1)
 
130
  return Transcribe()
131
  else:
132
  raise gr.Error("There is some issue ith Video Transcriber. Please try again later!")
@@ -154,6 +163,7 @@ def YoutubeTranscribe(NumberOfSpeakers=None, SpeakerNames="", URL="", retries =
154
  stream = ffmpeg.input('temp_audio.m4a')
155
  stream = ffmpeg.output(stream, 'temp_audio.wav')
156
  RemoveFile("temp_audio.m4a")
 
157
  return Transcribe()
158
  else:
159
  raise gr.Error(f"Unable to get video from {URL}")
 
11
  import traceback
12
  import json
13
  pipeline = Pipeline.from_pretrained("pyannote/speaker-diarization", use_auth_token="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")
14
+ from pydub.effects import speedup
15
+
16
+ def ChangeAudioRate(audio):
17
+ audio = AudioSegment.from_wav(audio)
18
+ new_file = speedup(audio,0.9,90)
19
+ new_file.export(audio, format="wav")
20
+
21
  __FILES = set()
22
 
23
  def CreateFile(filename):
 
120
  return AudioTranscribe(audio, retries-1)
121
  if not (os.path.isfile("temp_audio.wav")):
122
  return AudioTranscribe(audio, retries-1)
123
+ ChangeAudioRate("temp_audio.wav")
124
  return Transcribe()
125
  else:
126
  raise gr.Error("There is some issue ith Audio Transcriber. Please try again later!")
 
135
  return VideoTranscribe(video, retries-1)
136
  if not (os.path.isfile("temp_audio.wav")):
137
  return VideoTranscribe(video, retries-1)
138
+ ChangeAudioRate("temp_audio.wav")
139
  return Transcribe()
140
  else:
141
  raise gr.Error("There is some issue ith Video Transcriber. Please try again later!")
 
163
  stream = ffmpeg.input('temp_audio.m4a')
164
  stream = ffmpeg.output(stream, 'temp_audio.wav')
165
  RemoveFile("temp_audio.m4a")
166
+ ChangeAudioRate("temp_audio.wav")
167
  return Transcribe()
168
  else:
169
  raise gr.Error(f"Unable to get video from {URL}")