LittleLirow commited on
Commit
99500b3
1 Parent(s): 7750198

Updated voice generation to direct HTTP request

Browse files
Files changed (2) hide show
  1. app.py +1 -1
  2. narrator.py +25 -7
app.py CHANGED
@@ -8,7 +8,7 @@ import gradio as gr
8
 
9
  def generate_video(text, auth_openai, auth_elevenlabs, auth_replicate, auth_rev):
10
  generated_story = story.text2story(text, auth_openai)
11
- narrator.text2voice(generated_story, "audio_out.mp3", auth_elevenlabs, 5)
12
  deforum_str, max_frames = subtitles.audio2subtitle(auth_rev)
13
  animation.story2video(deforum_str, max_frames, auth_replicate)
14
  # generated_music = bgm.text2audio(text=text, duration=20, guidance_scale=5, random_seed=24, n_candidates=3)
 
8
 
9
  def generate_video(text, auth_openai, auth_elevenlabs, auth_replicate, auth_rev):
10
  generated_story = story.text2story(text, auth_openai)
11
+ narrator.text2voice(generated_story, "audio_out.mp3", auth_elevenlabs)
12
  deforum_str, max_frames = subtitles.audio2subtitle(auth_rev)
13
  animation.story2video(deforum_str, max_frames, auth_replicate)
14
  # generated_music = bgm.text2audio(text=text, duration=20, guidance_scale=5, random_seed=24, n_candidates=3)
narrator.py CHANGED
@@ -1,9 +1,27 @@
1
- from elevenlabslib import *
2
  import os
3
 
4
- def text2voice(prompt, path, key, voiceIndex):
5
- user = ElevenLabsUser(key)
6
- voice = user.get_available_voices()[voiceIndex]
7
- audioBytes = voice.generate_audio_bytes(prompt)
8
- with open(path, "wb") as binary_file:
9
- binary_file.write(audioBytes)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
  import os
3
 
4
+ CHUNK_SIZE = 1024
5
+ url = "https://api.elevenlabs.io/v1/text-to-speech/TxGEqnHWrfWFTfGW9XjX"
6
+
7
+ def text2voice(prompt, path, key):
8
+ headers = {
9
+ "Accept": "audio/mpeg",
10
+ "Content-Type": "application/json",
11
+ "xi-api-key": f"{key}"
12
+ }
13
+
14
+ data = {
15
+ "text": f"{prompt}",
16
+ "voice_settings": {
17
+ "stability": 0,
18
+ "similarity_boost": 0
19
+ }
20
+ }
21
+
22
+ response = requests.post(url, json=data, headers=headers, stream=True)
23
+
24
+ with open(path, 'wb') as f:
25
+ for chunk in response.iter_content(chunk_size=CHUNK_SIZE):
26
+ if chunk:
27
+ f.write(chunk)