PyxiLabs commited on
Commit
de2353d
·
verified ·
1 Parent(s): 3c470f5

Update vocify.py

Browse files
Files changed (1) hide show
  1. vocify.py +9 -11
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 == 200:
60
- audio_segment = AudioSegment.from_file(io.BytesIO(response.content), format="mp3")
61
- combined_audio += audio_segment
62
- else:
63
- print(f"Failed to generate speech for chunk: {response.status_code}, {response.text}")
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 == 200:
82
- return response.content
83
- else:
84
- print(f"Failed to generate speech: {response.status_code}, {response.text}")
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