Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +18 -5
- requirements.txt +2 -1
app.py
CHANGED
|
@@ -26,10 +26,17 @@ def get_audio_duration(filename):
|
|
| 26 |
|
| 27 |
|
| 28 |
def transcribe_single(audio_file):
|
| 29 |
-
# 存储原始上传文件
|
| 30 |
input_path = "audio.mp3"
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
# Step 1: 静音检测
|
| 35 |
silence_cmd = f"ffmpeg -i {input_path} -af silencedetect=noise=-30dB:d=1 -f null - 2> silence_log.txt"
|
|
@@ -91,8 +98,14 @@ def transcribe_single(audio_file):
|
|
| 91 |
|
| 92 |
def transcribe_multi(audio_file):
|
| 93 |
input_path = "audio_multi.mp3"
|
| 94 |
-
|
| 95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
diarization = diarization_pipeline(input_path)
|
| 98 |
segments = []
|
|
|
|
| 26 |
|
| 27 |
|
| 28 |
def transcribe_single(audio_file):
|
|
|
|
| 29 |
input_path = "audio.mp3"
|
| 30 |
+
|
| 31 |
+
# 判断是否是 bytes-like 文件
|
| 32 |
+
if hasattr(audio_file, "read"):
|
| 33 |
+
with open(input_path, "wb") as f:
|
| 34 |
+
f.write(audio_file.read())
|
| 35 |
+
else:
|
| 36 |
+
# 如果是 (numpy_array, sr) 格式
|
| 37 |
+
import soundfile as sf
|
| 38 |
+
waveform, sample_rate = audio_file
|
| 39 |
+
sf.write(input_path, waveform, sample_rate)
|
| 40 |
|
| 41 |
# Step 1: 静音检测
|
| 42 |
silence_cmd = f"ffmpeg -i {input_path} -af silencedetect=noise=-30dB:d=1 -f null - 2> silence_log.txt"
|
|
|
|
| 98 |
|
| 99 |
def transcribe_multi(audio_file):
|
| 100 |
input_path = "audio_multi.mp3"
|
| 101 |
+
|
| 102 |
+
if hasattr(audio_file, "read"):
|
| 103 |
+
with open(input_path, "wb") as f:
|
| 104 |
+
f.write(audio_file.read())
|
| 105 |
+
else:
|
| 106 |
+
import soundfile as sf
|
| 107 |
+
waveform, sample_rate = audio_file
|
| 108 |
+
sf.write(input_path, waveform, sample_rate)
|
| 109 |
|
| 110 |
diarization = diarization_pipeline(input_path)
|
| 111 |
segments = []
|
requirements.txt
CHANGED
|
@@ -3,4 +3,5 @@ git+https://github.com/openai/whisper.git
|
|
| 3 |
ffmpeg-python
|
| 4 |
setuptools-rust
|
| 5 |
# PyAnnote 音频说话人分离(推荐 pin 版本)
|
| 6 |
-
pyannote.audio>=2.1.1
|
|
|
|
|
|
| 3 |
ffmpeg-python
|
| 4 |
setuptools-rust
|
| 5 |
# PyAnnote 音频说话人分离(推荐 pin 版本)
|
| 6 |
+
pyannote.audio>=2.1.1
|
| 7 |
+
soundfile
|