malek-messaoudii commited on
Commit
4f1c42b
·
1 Parent(s): 14f424f

Update tts_service.py

Browse files
Files changed (1) hide show
  1. services/tts_service.py +7 -3
services/tts_service.py CHANGED
@@ -1,9 +1,10 @@
1
  from services.gemini_client import get_gemini_client
2
  from google.genai import types
 
3
 
4
  async def generate_tts(text: str) -> bytes:
5
  """
6
- Convert text to speech using Gemini API
7
  """
8
  client = get_gemini_client()
9
 
@@ -20,5 +21,8 @@ async def generate_tts(text: str) -> bytes:
20
  ),
21
  )
22
 
23
- # Return raw audio bytes
24
- return response.candidates[0].content.parts[0].inline_data.data
 
 
 
 
1
  from services.gemini_client import get_gemini_client
2
  from google.genai import types
3
+ import base64
4
 
5
  async def generate_tts(text: str) -> bytes:
6
  """
7
+ Convert text to speech using Gemini API and return valid WAV bytes
8
  """
9
  client = get_gemini_client()
10
 
 
21
  ),
22
  )
23
 
24
+ # Gemini returns base64 audio, decode it to bytes
25
+ audio_base64 = response.candidates[0].content.parts[0].inline_data.data
26
+ audio_bytes = base64.b64decode(audio_base64)
27
+
28
+ return audio_bytes