Spaces:
Build error
Build error
Update audio_processing.py
Browse files- audio_processing.py +5 -0
audio_processing.py
CHANGED
@@ -3,6 +3,7 @@ import whisper
|
|
3 |
import numpy as np
|
4 |
import torchaudio as ta
|
5 |
import gradio as gr
|
|
|
6 |
from model_utils import get_processor, get_model, get_whisper_model_small, get_device
|
7 |
from config import SAMPLING_RATE, CHUNK_LENGTH_S
|
8 |
import subprocess
|
@@ -10,12 +11,14 @@ import subprocess
|
|
10 |
import subprocess
|
11 |
import torchaudio as ta
|
12 |
|
|
|
13 |
def resample_with_ffmpeg(input_file, output_file, target_sr=16000):
|
14 |
command = [
|
15 |
'ffmpeg', '-i', input_file, '-ar', str(target_sr), output_file
|
16 |
]
|
17 |
subprocess.run(command, check=True)
|
18 |
|
|
|
19 |
def detect_language(audio):
|
20 |
whisper_model = get_whisper_model_small()
|
21 |
|
@@ -50,6 +53,7 @@ def detect_language(audio):
|
|
50 |
return detected_lang
|
51 |
|
52 |
|
|
|
53 |
def process_long_audio(audio, task="transcribe", language=None):
|
54 |
if audio[0] != SAMPLING_RATE:
|
55 |
# Save the input audio to a file for ffmpeg processing
|
@@ -106,6 +110,7 @@ def process_long_audio(audio, task="transcribe", language=None):
|
|
106 |
return " ".join(results)
|
107 |
|
108 |
|
|
|
109 |
def process_audio(audio):
|
110 |
if audio is None:
|
111 |
return "No file uploaded", "", ""
|
|
|
3 |
import numpy as np
|
4 |
import torchaudio as ta
|
5 |
import gradio as gr
|
6 |
+
import spaces
|
7 |
from model_utils import get_processor, get_model, get_whisper_model_small, get_device
|
8 |
from config import SAMPLING_RATE, CHUNK_LENGTH_S
|
9 |
import subprocess
|
|
|
11 |
import subprocess
|
12 |
import torchaudio as ta
|
13 |
|
14 |
+
|
15 |
def resample_with_ffmpeg(input_file, output_file, target_sr=16000):
|
16 |
command = [
|
17 |
'ffmpeg', '-i', input_file, '-ar', str(target_sr), output_file
|
18 |
]
|
19 |
subprocess.run(command, check=True)
|
20 |
|
21 |
+
+@spaces.GPU
|
22 |
def detect_language(audio):
|
23 |
whisper_model = get_whisper_model_small()
|
24 |
|
|
|
53 |
return detected_lang
|
54 |
|
55 |
|
56 |
+
+@spaces.GPU
|
57 |
def process_long_audio(audio, task="transcribe", language=None):
|
58 |
if audio[0] != SAMPLING_RATE:
|
59 |
# Save the input audio to a file for ffmpeg processing
|
|
|
110 |
return " ".join(results)
|
111 |
|
112 |
|
113 |
+
+@spaces.GPU
|
114 |
def process_audio(audio):
|
115 |
if audio is None:
|
116 |
return "No file uploaded", "", ""
|