Commit
·
41b9b54
1
Parent(s):
a524b41
changing ref_audio sending format to base64 (to solve error)
Browse files- handler.py +15 -3
handler.py
CHANGED
|
@@ -39,13 +39,25 @@ class EndpointHandler:
|
|
| 39 |
|
| 40 |
def __call__(self, data: Dict[str, Any]) -> Dict[str, Any]:
|
| 41 |
try:
|
| 42 |
-
|
| 43 |
-
if not
|
| 44 |
return {
|
| 45 |
"success": False,
|
| 46 |
"error": "Missing required field: 'ref_audio'"
|
| 47 |
}
|
| 48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
ref_text = data.get("ref_text", "")
|
| 50 |
gen_text = data.get("gen_text", "")
|
| 51 |
if not gen_text:
|
|
@@ -58,7 +70,7 @@ class EndpointHandler:
|
|
| 58 |
cross_fade_duration = data.get("cross_fade_duration", 0.15)
|
| 59 |
speed = data.get("speed", 1.0)
|
| 60 |
|
| 61 |
-
ref_audio, ref_text = preprocess_ref_audio_text(
|
| 62 |
|
| 63 |
if not gen_text.startswith(" "):
|
| 64 |
gen_text = " " + gen_text
|
|
|
|
| 39 |
|
| 40 |
def __call__(self, data: Dict[str, Any]) -> Dict[str, Any]:
|
| 41 |
try:
|
| 42 |
+
ref_audio_base64 = data.get("ref_audio")
|
| 43 |
+
if not ref_audio_base64:
|
| 44 |
return {
|
| 45 |
"success": False,
|
| 46 |
"error": "Missing required field: 'ref_audio'"
|
| 47 |
}
|
| 48 |
|
| 49 |
+
# Decode base64 audio and write to temp file
|
| 50 |
+
try:
|
| 51 |
+
audio_bytes = base64.b64decode(ref_audio_base64)
|
| 52 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as temp_audio_file:
|
| 53 |
+
temp_audio_file.write(audio_bytes)
|
| 54 |
+
temp_audio_path = temp_audio_file.name
|
| 55 |
+
except Exception as e:
|
| 56 |
+
return {
|
| 57 |
+
"success": False,
|
| 58 |
+
"error": f"Invalid audio data: {type(e).__name__}: {str(e)}"
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
ref_text = data.get("ref_text", "")
|
| 62 |
gen_text = data.get("gen_text", "")
|
| 63 |
if not gen_text:
|
|
|
|
| 70 |
cross_fade_duration = data.get("cross_fade_duration", 0.15)
|
| 71 |
speed = data.get("speed", 1.0)
|
| 72 |
|
| 73 |
+
ref_audio, ref_text = preprocess_ref_audio_text(temp_audio_path, ref_text, show_info=print)
|
| 74 |
|
| 75 |
if not gen_text.startswith(" "):
|
| 76 |
gen_text = " " + gen_text
|