Jofthomas HF staff commited on
Commit
28f4321
1 Parent(s): ce88b36

Update TextGen/router.py

Browse files
Files changed (1) hide show
  1. TextGen/router.py +15 -8
TextGen/router.py CHANGED
@@ -20,7 +20,7 @@ from TextGen import app
20
  from gradio_client import Client, handle_file
21
  from typing import List
22
  from elevenlabs.client import ElevenLabs
23
- from elevenlabs import stream
24
 
25
 
26
  Eleven_client = ElevenLabs(
@@ -74,9 +74,9 @@ main_npcs={
74
  "Bard":"./voices/Bard_voice.mp3"
75
  }
76
  main_npcs_elevenlabs={
77
- "Blacksmith":"",
78
- "Herbalist":"",
79
- "Bard":""
80
  }
81
  main_npc_system_prompts={
82
  "Blacksmith":"You are a blacksmith in a video game",
@@ -193,11 +193,11 @@ def determine_elevenLav_voice_from_npc(npc,genre):
193
  return main_npcs[npc]
194
  else:
195
  if genre =="Male":
196
- "./voices/default_male.mp3"
197
  if genre=="Female":
198
- return"./voices/default_female.mp3"
199
  else:
200
- return "./voices/narator_out.wav"
201
 
202
  @app.post("/generate_wav")
203
  async def generate_wav(message: VoiceMessage):
@@ -240,8 +240,15 @@ def generate_voice_eleven(message: VoiceMessage = None):
240
  Last_message = message
241
 
242
  def audio_stream():
 
 
243
  # Generate the audio stream from ElevenLabs
244
- for chunk in Eleven_client.generate(text=message.input, stream=True):
 
 
 
 
 
245
  yield chunk
246
 
247
  return StreamingResponse(audio_stream(), media_type="audio/mpeg")
 
20
  from gradio_client import Client, handle_file
21
  from typing import List
22
  from elevenlabs.client import ElevenLabs
23
+ from elevenlabs import Voice, VoiceSettings, stream
24
 
25
 
26
  Eleven_client = ElevenLabs(
 
74
  "Bard":"./voices/Bard_voice.mp3"
75
  }
76
  main_npcs_elevenlabs={
77
+ "Blacksmith":"yYdk7n49vTsUKiXxnosS",
78
+ "Herbalist":"143zSsxc4O5ifS97lPCa",
79
+ "Bard":"143zSsxc4O5ifS97lPCa"
80
  }
81
  main_npc_system_prompts={
82
  "Blacksmith":"You are a blacksmith in a video game",
 
193
  return main_npcs[npc]
194
  else:
195
  if genre =="Male":
196
+ "bIHbv24MWmeRgasZH58o"
197
  if genre=="Female":
198
+ return"pFZP5JQG7iQjIQuC4Bku"
199
  else:
200
+ return "TX3LPaxmHKxFdv7VOQHJ"
201
 
202
  @app.post("/generate_wav")
203
  async def generate_wav(message: VoiceMessage):
 
240
  Last_message = message
241
 
242
  def audio_stream():
243
+ this_voice_id=determine_elevenLav_voice_from_npc(message.npc, message.genre)
244
+
245
  # Generate the audio stream from ElevenLabs
246
+ for chunk in Eleven_client.generate(text=message.input,
247
+ voice=Voice(
248
+ voice_id=this_voice_id,
249
+ settings=VoiceSettings(stability=0.71, similarity_boost=0.5, style=0.0, use_speaker_boost=True)
250
+ ),
251
+ stream=True):
252
  yield chunk
253
 
254
  return StreamingResponse(audio_stream(), media_type="audio/mpeg")