Update xtts.py
Browse files
xtts.py
CHANGED
|
@@ -48,6 +48,8 @@ def predict(text, sample=None, language="zh"):
|
|
| 48 |
file_path=output
|
| 49 |
)
|
| 50 |
|
|
|
|
|
|
|
| 51 |
return upload(output)
|
| 52 |
|
| 53 |
with io.BytesIO() as wav_buffer:
|
|
@@ -135,6 +137,23 @@ def trim_sample_audio(speaker_wav):
|
|
| 135 |
traceback.print_exc()
|
| 136 |
return speaker_wav
|
| 137 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
from flask import Flask, request
|
| 139 |
app = Flask(__name__)
|
| 140 |
@app.route("/tts")
|
|
|
|
| 48 |
file_path=output
|
| 49 |
)
|
| 50 |
|
| 51 |
+
output=to_mp3(output)
|
| 52 |
+
|
| 53 |
return upload(output)
|
| 54 |
|
| 55 |
with io.BytesIO() as wav_buffer:
|
|
|
|
| 137 |
traceback.print_exc()
|
| 138 |
return speaker_wav
|
| 139 |
|
| 140 |
+
def to_mp3(wav):
|
| 141 |
+
global ffmpeg
|
| 142 |
+
try:
|
| 143 |
+
mp3=tempfile.mktemp(suffix=".mp3")
|
| 144 |
+
shell_command = f"{ffmpeg} -i {wav} {mp3}".split(" ")
|
| 145 |
+
subprocess.run(
|
| 146 |
+
[item for item in shell_command],
|
| 147 |
+
capture_output=False,
|
| 148 |
+
text=True,
|
| 149 |
+
check=True,
|
| 150 |
+
)
|
| 151 |
+
return mp3
|
| 152 |
+
except:
|
| 153 |
+
traceback.print_exc()
|
| 154 |
+
return wav
|
| 155 |
+
|
| 156 |
+
|
| 157 |
from flask import Flask, request
|
| 158 |
app = Flask(__name__)
|
| 159 |
@app.route("/tts")
|