Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ import torch
|
|
3 |
import gradio as gr
|
4 |
import librosa
|
5 |
import numpy as np
|
|
|
6 |
|
7 |
p = pipeline("automatic-speech-recognition", model="aware-ai/wav2vec2-base-german")
|
8 |
|
@@ -19,24 +20,26 @@ def is_speech(wav, sr):
|
|
19 |
|
20 |
return len(speech_timestamps) > 0
|
21 |
|
22 |
-
def transcribe(audio, state={"text": "", "temp_text": "", "audio":
|
23 |
if state is None:
|
24 |
-
state={"text": "", "temp_text": "", "audio":
|
25 |
wav_data, _sr = librosa.load(audio, sr=16000)
|
26 |
speech = is_speech(wav_data, _sr)
|
27 |
if(speech):
|
28 |
-
if(state["audio"] is
|
29 |
state["audio"] = wav_data
|
30 |
else:
|
31 |
state["audio"] = np.concatenate((state["audio"], wav_data))
|
32 |
-
|
33 |
-
text = p(state["audio"])["text"] + "\n"
|
34 |
-
state["temp_text"] = text
|
35 |
else:
|
|
|
|
|
|
|
|
|
36 |
state["text"] += state["temp_text"]
|
37 |
state["temp_text"] = ""
|
38 |
-
state["audio"] =
|
39 |
|
|
|
40 |
return f'{state["text"]} ( {state["temp_text"]} )', state
|
41 |
|
42 |
gr.Interface(
|
|
|
3 |
import gradio as gr
|
4 |
import librosa
|
5 |
import numpy as np
|
6 |
+
import time
|
7 |
|
8 |
p = pipeline("automatic-speech-recognition", model="aware-ai/wav2vec2-base-german")
|
9 |
|
|
|
20 |
|
21 |
return len(speech_timestamps) > 0
|
22 |
|
23 |
+
def transcribe(audio, state={"text": "", "temp_text": "", "audio": ""}):
|
24 |
if state is None:
|
25 |
+
state={"text": "", "temp_text": "", "audio": ""}
|
26 |
wav_data, _sr = librosa.load(audio, sr=16000)
|
27 |
speech = is_speech(wav_data, _sr)
|
28 |
if(speech):
|
29 |
+
if(state["audio"] is ""):
|
30 |
state["audio"] = wav_data
|
31 |
else:
|
32 |
state["audio"] = np.concatenate((state["audio"], wav_data))
|
|
|
|
|
|
|
33 |
else:
|
34 |
+
if(state["audio"] is not ""):
|
35 |
+
text = p(state["audio"])["text"] + "\n"
|
36 |
+
state["temp_text"] = text
|
37 |
+
|
38 |
state["text"] += state["temp_text"]
|
39 |
state["temp_text"] = ""
|
40 |
+
state["audio"] = ""
|
41 |
|
42 |
+
time.sleep(0.5)
|
43 |
return f'{state["text"]} ( {state["temp_text"]} )', state
|
44 |
|
45 |
gr.Interface(
|