li cheng commited on
Commit
b9ae40e
·
1 Parent(s): 2bc4022

try sample threshold/2 until 0.001

Browse files
Files changed (1) hide show
  1. xtts.py +10 -6
xtts.py CHANGED
@@ -96,8 +96,8 @@ def download_sample(url):
96
  response = requests.get(url)
97
  if response.status_code == 200:
98
  id=f'{sample_root}/{response.headers["etag"]}.pt'.replace('"','')
99
- if(os.path.exists(id)):
100
- return "", id
101
  with tempfile.NamedTemporaryFile(mode="wb", suffix=".wav", delete=False) as temp_file:
102
  temp_file.write(response.content)
103
  logging.debug(f'downloaded sample wav from {url}')
@@ -112,22 +112,26 @@ def download(url):
112
  temp_file.write(response.content)
113
  return os.path.abspath(temp_file.name)
114
 
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
 
96
  response = requests.get(url)
97
  if response.status_code == 200:
98
  id=f'{sample_root}/{response.headers["etag"]}.pt'.replace('"','')
99
+ # if(os.path.exists(id)):
100
+ # return "", id
101
  with tempfile.NamedTemporaryFile(mode="wb", suffix=".wav", delete=False) as temp_file:
102
  temp_file.write(response.content)
103
  logging.debug(f'downloaded sample wav from {url}')
 
112
  temp_file.write(response.content)
113
  return os.path.abspath(temp_file.name)
114
 
115
+ def trim_sample_audio(speaker_wav, threshold=0.005):
116
  global ffmpeg
117
  try:
 
118
  lowpass_highpass = "lowpass=8000,highpass=75,"
119
  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},"
120
  out_filename=speaker_wav.replace(".wav","_trimed.wav")
121
  shell_command = f"{ffmpeg} -y -i {speaker_wav} -af {lowpass_highpass}{trim_silence} {out_filename}".split(" ")
122
+ logging.debug(shell_command)
123
  result=subprocess.run(
124
  [item for item in shell_command],
125
+ capture_output=True,
126
  text=True,
127
  check=True,
128
  stdout=subprocess.DEVNULL,
129
+ stderr=None,
130
  )
131
+ if result.stderr is not None and "Output file is empty" in result.stderr:
132
+ if threshold > 0.001:
133
+ return trim_sample_audio(speaker_wav, threshold/2)
134
+ return speaker_wav
135
  os.remove(speaker_wav)
136
  logging.debug(f'trimed sample wav to {out_filename}')
137
  return out_filename