Spaces:
Running
on
Zero
Running
on
Zero
better debug information
Browse files
OmniAvatar/utils/audio_preprocess.py
CHANGED
|
@@ -1,18 +1,21 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import subprocess
|
| 3 |
-
|
| 4 |
-
def add_silence_to_audio_ffmpeg(audio_path, tmp_audio_path, silence_duration_s=0.5):
|
| 5 |
-
# 使用 ffmpeg 命令在音频前加上静音
|
| 6 |
-
|
| 7 |
-
'ffmpeg',
|
| 8 |
-
'-i', audio_path, # 输入音频文件路径
|
| 9 |
-
'-f', 'lavfi', # 使用 lavfi 虚拟输入设备生成静音
|
| 10 |
-
'-t', str(silence_duration_s), # 静音时长,单位秒
|
| 11 |
-
'-i', 'anullsrc=r=16000:cl=stereo', # 创建静音片段(假设音频为 stereo,采样率 44100)
|
| 12 |
-
'-filter_complex', '[1][0]concat=n=2:v=0:a=1[out]', # 合并静音和原音频
|
| 13 |
-
'-map', '[out]', # 输出合并后的音频
|
| 14 |
-
'-y', tmp_audio_path, # 输出文件路径
|
| 15 |
-
'-loglevel', '
|
| 16 |
-
]
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import subprocess
|
| 3 |
+
|
| 4 |
+
def add_silence_to_audio_ffmpeg(audio_path, tmp_audio_path, silence_duration_s=0.5):
|
| 5 |
+
# 使用 ffmpeg 命令在音频前加上静音
|
| 6 |
+
cmd = [
|
| 7 |
+
'ffmpeg',
|
| 8 |
+
'-i', audio_path, # 输入音频文件路径
|
| 9 |
+
'-f', 'lavfi', # 使用 lavfi 虚拟输入设备生成静音
|
| 10 |
+
'-t', str(silence_duration_s), # 静音时长,单位秒
|
| 11 |
+
'-i', 'anullsrc=r=16000:cl=stereo', # 创建静音片段(假设音频为 stereo,采样率 44100)
|
| 12 |
+
'-filter_complex', '[1][0]concat=n=2:v=0:a=1[out]', # 合并静音和原音频
|
| 13 |
+
'-map', '[out]', # 输出合并后的音频
|
| 14 |
+
'-y', tmp_audio_path, # 输出文件路径
|
| 15 |
+
'-loglevel', 'error'
|
| 16 |
+
]
|
| 17 |
+
|
| 18 |
+
try:
|
| 19 |
+
subprocess.run(cmd, check=True, capture_output=True, text=True)
|
| 20 |
+
except subprocess.CalledProcessError as e:
|
| 21 |
+
raise RuntimeError(f"ffmpeg failed ({e.returncode}): {e.stderr.strip()}")
|