Update vocify.py
Browse files
vocify.py
CHANGED
|
@@ -56,12 +56,11 @@ def generate_speech(voice, input_text, model="eleven_multilingual_v2"):
|
|
| 56 |
"model_id": model,
|
| 57 |
}
|
| 58 |
response = requests.post(url, json=data, headers=headers)
|
| 59 |
-
if response.status_code
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
return [response.status_code, response.text]
|
| 65 |
# Export the combined audio to a BytesIO object
|
| 66 |
combined_audio_bytes = io.BytesIO()
|
| 67 |
combined_audio.export(combined_audio_bytes, format="mp3")
|
|
@@ -78,8 +77,7 @@ def generate_speech(voice, input_text, model="eleven_multilingual_v2"):
|
|
| 78 |
"model_id": model,
|
| 79 |
}
|
| 80 |
response = requests.post(url, json=data, headers=headers)
|
| 81 |
-
if response.status_code
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
return [response.status_code, response.text]
|
|
|
|
| 56 |
"model_id": model,
|
| 57 |
}
|
| 58 |
response = requests.post(url, json=data, headers=headers)
|
| 59 |
+
if response.status_code != 200:
|
| 60 |
+
# Raise an exception if the API response is not 200
|
| 61 |
+
raise Exception(f"Failed to generate speech for chunk: {response.status_code}, {response.text}")
|
| 62 |
+
audio_segment = AudioSegment.from_file(io.BytesIO(response.content), format="mp3")
|
| 63 |
+
combined_audio += audio_segment
|
|
|
|
| 64 |
# Export the combined audio to a BytesIO object
|
| 65 |
combined_audio_bytes = io.BytesIO()
|
| 66 |
combined_audio.export(combined_audio_bytes, format="mp3")
|
|
|
|
| 77 |
"model_id": model,
|
| 78 |
}
|
| 79 |
response = requests.post(url, json=data, headers=headers)
|
| 80 |
+
if response.status_code != 200:
|
| 81 |
+
# Raise an exception if the API response is not 200
|
| 82 |
+
raise Exception(f"Failed to generate speech: {response.status_code}")
|
| 83 |
+
return response.content
|
|
|