li cheng
commited on
Commit
·
2bc4022
1
Parent(s):
e73f150
sample silence threshold
Browse files
xtts.py
CHANGED
@@ -3,6 +3,7 @@ import requests
|
|
3 |
import torch
|
4 |
import traceback
|
5 |
from TTS.api import TTS
|
|
|
6 |
|
7 |
root=os.path.dirname(os.path.abspath(__file__))
|
8 |
|
@@ -26,7 +27,7 @@ if not os.path.exists(sample_root):
|
|
26 |
os.makedirs(sample_root)
|
27 |
default_sample=f'{root}/sample.wav', f'{sample_root}/sample.pt'
|
28 |
|
29 |
-
ffmpeg=f'{root}/ffmpeg'
|
30 |
|
31 |
if api:
|
32 |
from qili import upload, check_token
|
@@ -114,25 +115,22 @@ def download(url):
|
|
114 |
def trim_sample_audio(speaker_wav):
|
115 |
global ffmpeg
|
116 |
try:
|
|
|
117 |
lowpass_highpass = "lowpass=8000,highpass=75,"
|
118 |
-
trim_silence = "areverse,silenceremove=start_periods=1:start_silence=0:start_threshold=
|
119 |
out_filename=speaker_wav.replace(".wav","_trimed.wav")
|
120 |
shell_command = f"{ffmpeg} -y -i {speaker_wav} -af {lowpass_highpass}{trim_silence} {out_filename}".split(" ")
|
121 |
-
subprocess.run(
|
122 |
[item for item in shell_command],
|
123 |
capture_output=False,
|
124 |
text=True,
|
125 |
check=True,
|
126 |
-
stdout=
|
127 |
stderr=None, #subprocess.PIPE,
|
128 |
)
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
return out_filename
|
133 |
-
else:
|
134 |
-
logging.debug(f'Error: trimed sample wav to, ignored')
|
135 |
-
return speaker_wav
|
136 |
except:
|
137 |
logging.debug(f'Error: trimed sample wav to, ignored')
|
138 |
return speaker_wav
|
@@ -147,8 +145,8 @@ def to_mp3(wav):
|
|
147 |
capture_output=False,
|
148 |
text=True,
|
149 |
check=True,
|
150 |
-
stdout=
|
151 |
-
stderr=
|
152 |
)
|
153 |
logging.debug(f'convert wav {wav} to mp3 at {mp3}')
|
154 |
return mp3
|
|
|
3 |
import torch
|
4 |
import traceback
|
5 |
from TTS.api import TTS
|
6 |
+
#ffmpeg -y -i /var/folders/w6/mxy2wbmd2bj360glkp0d5qbw0000gn/T/tmp49s6gxk7.wav -af lowpass=8000,highpass=75,areverse,silenceremove=start_periods=1:start_silence=0:start_threshold=0.02,areverse,silenceremove=start_periods=1:start_silence=0:start_threshold=0.02, ./test.wav
|
7 |
|
8 |
root=os.path.dirname(os.path.abspath(__file__))
|
9 |
|
|
|
27 |
os.makedirs(sample_root)
|
28 |
default_sample=f'{root}/sample.wav', f'{sample_root}/sample.pt'
|
29 |
|
30 |
+
ffmpeg="/opt/homebrew/bin/ffmpeg" #f'{root}/ffmpeg'
|
31 |
|
32 |
if api:
|
33 |
from qili import upload, check_token
|
|
|
115 |
def trim_sample_audio(speaker_wav):
|
116 |
global ffmpeg
|
117 |
try:
|
118 |
+
threshold=0.005 #os.environ["FILTER_THRESHOLD"]
|
119 |
lowpass_highpass = "lowpass=8000,highpass=75,"
|
120 |
+
trim_silence = f"areverse,silenceremove=start_periods=1:start_silence=0:start_threshold={threshold},areverse,silenceremove=start_periods=1:start_silence=0:start_threshold={threshold},"
|
121 |
out_filename=speaker_wav.replace(".wav","_trimed.wav")
|
122 |
shell_command = f"{ffmpeg} -y -i {speaker_wav} -af {lowpass_highpass}{trim_silence} {out_filename}".split(" ")
|
123 |
+
result=subprocess.run(
|
124 |
[item for item in shell_command],
|
125 |
capture_output=False,
|
126 |
text=True,
|
127 |
check=True,
|
128 |
+
stdout=subprocess.DEVNULL,
|
129 |
stderr=None, #subprocess.PIPE,
|
130 |
)
|
131 |
+
os.remove(speaker_wav)
|
132 |
+
logging.debug(f'trimed sample wav to {out_filename}')
|
133 |
+
return out_filename
|
|
|
|
|
|
|
|
|
134 |
except:
|
135 |
logging.debug(f'Error: trimed sample wav to, ignored')
|
136 |
return speaker_wav
|
|
|
145 |
capture_output=False,
|
146 |
text=True,
|
147 |
check=True,
|
148 |
+
stdout=subprocess.DEVNULL,
|
149 |
+
stderr=subprocess.DEVNULL,
|
150 |
)
|
151 |
logging.debug(f'convert wav {wav} to mp3 at {mp3}')
|
152 |
return mp3
|