Spaces:
Runtime error
Runtime error
Commit
·
d174120
1
Parent(s):
9bcd364
Update app.py
Browse files
app.py
CHANGED
@@ -15,6 +15,17 @@ from pydub.effects import speedup
|
|
15 |
|
16 |
|
17 |
__FILES = set()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
def CreateFile(filename):
|
20 |
__FILES.add(filename)
|
@@ -29,7 +40,7 @@ def RemoveAllFiles():
|
|
29 |
if (os.path.isfile(file)):
|
30 |
os.remove(file)
|
31 |
|
32 |
-
def Transcribe(audio="temp_audio.wav"):
|
33 |
def millisec(timeStr):
|
34 |
spl = timeStr.split(":")
|
35 |
s = (int)((int(spl[0]) * 60 * 60 + int(spl[1]) * 60 + float(spl[2]) )* 1000)
|
@@ -58,7 +69,7 @@ def Transcribe(audio="temp_audio.wav"):
|
|
58 |
start, end = tuple(re.findall('[0-9]+:[0-9]+:[0-9]+\.[0-9]+', string=l))
|
59 |
start = millisec(start)
|
60 |
end = millisec(end)
|
61 |
-
lex = re.findall('(SPEAKER_[0-9][0-9])', string=l)[0]
|
62 |
dzList.append([start, end, lex])
|
63 |
sounds = spacer
|
64 |
segments = []
|
@@ -101,6 +112,7 @@ def Transcribe(audio="temp_audio.wav"):
|
|
101 |
#print(f"[{dzList[i][2]}] {c[2]}")
|
102 |
return conversation, ("".join([f"{speaker} --> {text}\n" for speaker, text in conversation]))
|
103 |
|
|
|
104 |
spacermilli, spacer = preprocess(audio)
|
105 |
dz_audio, dzList, segments = diarization(audio)
|
106 |
conversation, t_text = transcribe(dz_audio)
|
@@ -116,7 +128,7 @@ def AudioTranscribe(NumberOfSpeakers=None, SpeakerNames="", audio="", retries=5)
|
|
116 |
return AudioTranscribe(audio, retries-1)
|
117 |
if not (os.path.isfile("temp_audio.wav")):
|
118 |
return AudioTranscribe(audio, retries-1)
|
119 |
-
return Transcribe()
|
120 |
else:
|
121 |
raise gr.Error("There is some issue ith Audio Transcriber. Please try again later!")
|
122 |
|
@@ -130,10 +142,10 @@ def VideoTranscribe(NumberOfSpeakers=None, SpeakerNames="", video="", retries=5)
|
|
130 |
return VideoTranscribe(video, retries-1)
|
131 |
if not (os.path.isfile("temp_audio.wav")):
|
132 |
return VideoTranscribe(video, retries-1)
|
133 |
-
return Transcribe()
|
134 |
else:
|
135 |
raise gr.Error("There is some issue ith Video Transcriber. Please try again later!")
|
136 |
-
return Transcribe()
|
137 |
|
138 |
def YoutubeTranscribe(NumberOfSpeakers=None, SpeakerNames="", URL="", retries = 5):
|
139 |
if retries:
|
@@ -157,7 +169,7 @@ def YoutubeTranscribe(NumberOfSpeakers=None, SpeakerNames="", URL="", retries =
|
|
157 |
stream = ffmpeg.input('temp_audio.m4a')
|
158 |
stream = ffmpeg.output(stream, 'temp_audio.wav')
|
159 |
RemoveFile("temp_audio.m4a")
|
160 |
-
return Transcribe()
|
161 |
else:
|
162 |
raise gr.Error(f"Unable to get video from {URL}")
|
163 |
|
|
|
15 |
|
16 |
|
17 |
__FILES = set()
|
18 |
+
SPEAKER_DICT = {}
|
19 |
+
SPEAKERS = []
|
20 |
+
|
21 |
+
def GetSpeaker(sp):
|
22 |
+
if sp not in list(SPEAKER_DICT.keys):
|
23 |
+
SPEAKER_DICT[sp] = SPEAKERS.pop(0)
|
24 |
+
return SPEAKER_DICT[sp]
|
25 |
+
|
26 |
+
def GenerateSpeakerDict(sp):
|
27 |
+
SPEAKERS = [speaker.strip() for speaker in sp.split(',')]
|
28 |
+
|
29 |
|
30 |
def CreateFile(filename):
|
31 |
__FILES.add(filename)
|
|
|
40 |
if (os.path.isfile(file)):
|
41 |
os.remove(file)
|
42 |
|
43 |
+
def Transcribe(NumberOfSpeakers, SpeakerNames="", audio="temp_audio.wav"):
|
44 |
def millisec(timeStr):
|
45 |
spl = timeStr.split(":")
|
46 |
s = (int)((int(spl[0]) * 60 * 60 + int(spl[1]) * 60 + float(spl[2]) )* 1000)
|
|
|
69 |
start, end = tuple(re.findall('[0-9]+:[0-9]+:[0-9]+\.[0-9]+', string=l))
|
70 |
start = millisec(start)
|
71 |
end = millisec(end)
|
72 |
+
lex = GetSpeaker(re.findall('(SPEAKER_[0-9][0-9])', string=l)[0])
|
73 |
dzList.append([start, end, lex])
|
74 |
sounds = spacer
|
75 |
segments = []
|
|
|
112 |
#print(f"[{dzList[i][2]}] {c[2]}")
|
113 |
return conversation, ("".join([f"{speaker} --> {text}\n" for speaker, text in conversation]))
|
114 |
|
115 |
+
GenerateSpeakerDict(SpeakerNames)
|
116 |
spacermilli, spacer = preprocess(audio)
|
117 |
dz_audio, dzList, segments = diarization(audio)
|
118 |
conversation, t_text = transcribe(dz_audio)
|
|
|
128 |
return AudioTranscribe(audio, retries-1)
|
129 |
if not (os.path.isfile("temp_audio.wav")):
|
130 |
return AudioTranscribe(audio, retries-1)
|
131 |
+
return Transcribe(NumberOfSpeakers, SpeakerNames)
|
132 |
else:
|
133 |
raise gr.Error("There is some issue ith Audio Transcriber. Please try again later!")
|
134 |
|
|
|
142 |
return VideoTranscribe(video, retries-1)
|
143 |
if not (os.path.isfile("temp_audio.wav")):
|
144 |
return VideoTranscribe(video, retries-1)
|
145 |
+
return Transcribe(NumberOfSpeakers, SpeakerNames)
|
146 |
else:
|
147 |
raise gr.Error("There is some issue ith Video Transcriber. Please try again later!")
|
148 |
+
return Transcribe(NumberOfSpeakers, SpeakerNames)
|
149 |
|
150 |
def YoutubeTranscribe(NumberOfSpeakers=None, SpeakerNames="", URL="", retries = 5):
|
151 |
if retries:
|
|
|
169 |
stream = ffmpeg.input('temp_audio.m4a')
|
170 |
stream = ffmpeg.output(stream, 'temp_audio.wav')
|
171 |
RemoveFile("temp_audio.m4a")
|
172 |
+
return Transcribe(NumberOfSpeakers, SpeakerNames)
|
173 |
else:
|
174 |
raise gr.Error(f"Unable to get video from {URL}")
|
175 |
|