Spaces:
Sleeping
Sleeping
update audio output debug
Browse files
api.py
CHANGED
|
@@ -4,6 +4,7 @@ import edge_tts
|
|
| 4 |
import soundfile as sf
|
| 5 |
import torch
|
| 6 |
import fairseq
|
|
|
|
| 7 |
from fastapi import FastAPI, HTTPException
|
| 8 |
from fastapi.responses import FileResponse
|
| 9 |
from pydantic import BaseModel
|
|
@@ -188,6 +189,12 @@ async def tts_api(req: TTSRequest):
|
|
| 188 |
# f.write(chunk["data"])
|
| 189 |
# await generate_tts_with_back4app(req.text, req.tts_voice, tts_wav)
|
| 190 |
await generate_tts_with_hf_space(req.text, req.tts_voice, tts_wav)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
except Exception as e:
|
| 192 |
raise HTTPException(status_code=500, detail=f"TTS error: {e}")
|
| 193 |
|
|
@@ -201,7 +208,7 @@ async def tts_api(req: TTSRequest):
|
|
| 201 |
raise Exception("Failed to load model")
|
| 202 |
|
| 203 |
# Run conversion menggunakan method single() yang benar
|
| 204 |
-
|
| 205 |
sid=0, # speaker id
|
| 206 |
input_audio=tts_wav, # path audio input
|
| 207 |
embedder_model_name="auto", # auto detect embedder
|
|
@@ -216,12 +223,21 @@ async def tts_api(req: TTSRequest):
|
|
| 216 |
output_dir=output_dir # output directory
|
| 217 |
)
|
| 218 |
|
| 219 |
-
# Cek apakah result
|
| 220 |
print("input_audio : ", tts_wav)
|
| 221 |
-
print("
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 225 |
sf.write(output_wav, audio_opt, tgt_sr)
|
| 226 |
except Exception as e:
|
| 227 |
raise HTTPException(status_code=500, detail=f"RVC exception error: {e}")
|
|
|
|
| 4 |
import soundfile as sf
|
| 5 |
import torch
|
| 6 |
import fairseq
|
| 7 |
+
import numpy as np
|
| 8 |
from fastapi import FastAPI, HTTPException
|
| 9 |
from fastapi.responses import FileResponse
|
| 10 |
from pydantic import BaseModel
|
|
|
|
| 189 |
# f.write(chunk["data"])
|
| 190 |
# await generate_tts_with_back4app(req.text, req.tts_voice, tts_wav)
|
| 191 |
await generate_tts_with_hf_space(req.text, req.tts_voice, tts_wav)
|
| 192 |
+
|
| 193 |
+
# Validasi file audio TTS
|
| 194 |
+
if not os.path.isfile(tts_wav):
|
| 195 |
+
raise HTTPException(status_code=500, detail="TTS file was not created")
|
| 196 |
+
if os.path.getsize(tts_wav) == 0:
|
| 197 |
+
raise HTTPException(status_code=500, detail="TTS file is empty")
|
| 198 |
except Exception as e:
|
| 199 |
raise HTTPException(status_code=500, detail=f"TTS error: {e}")
|
| 200 |
|
|
|
|
| 208 |
raise Exception("Failed to load model")
|
| 209 |
|
| 210 |
# Run conversion menggunakan method single() yang benar
|
| 211 |
+
audio_opt = vc.single(
|
| 212 |
sid=0, # speaker id
|
| 213 |
input_audio=tts_wav, # path audio input
|
| 214 |
embedder_model_name="auto", # auto detect embedder
|
|
|
|
| 223 |
output_dir=output_dir # output directory
|
| 224 |
)
|
| 225 |
|
| 226 |
+
# Cek apakah result adalah numpy array yang valid
|
| 227 |
print("input_audio : ", tts_wav)
|
| 228 |
+
print("audio_opt type: ", type(audio_opt))
|
| 229 |
+
print("audio_opt shape: ", audio_opt.shape if hasattr(audio_opt, 'shape') else 'N/A')
|
| 230 |
+
print("audio_opt sample: ", audio_opt[:10] if hasattr(audio_opt, '__getitem__') else 'N/A')
|
| 231 |
+
|
| 232 |
+
if not isinstance(audio_opt, np.ndarray):
|
| 233 |
+
raise HTTPException(status_code=500, detail=f"RVC error: Expected numpy array, got {type(audio_opt)}")
|
| 234 |
+
|
| 235 |
+
# Cek apakah audio_opt tidak kosong (tidak semua zeros)
|
| 236 |
+
if len(audio_opt) == 0 or np.all(audio_opt == 0):
|
| 237 |
+
raise HTTPException(status_code=500, detail="RVC error: Generated audio is empty or all zeros. Check input audio and model configuration.")
|
| 238 |
+
|
| 239 |
+
# Gunakan tgt_sr dari model
|
| 240 |
+
tgt_sr = vc.tgt_sr
|
| 241 |
sf.write(output_wav, audio_opt, tgt_sr)
|
| 242 |
except Exception as e:
|
| 243 |
raise HTTPException(status_code=500, detail=f"RVC exception error: {e}")
|