pvanand commited on
Commit
72440bd
1 Parent(s): 42db137

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +20 -11
main.py CHANGED
@@ -84,7 +84,7 @@ def get_api_keys():
84
  logger.info("Loading API keys")
85
  return {
86
  "OPENROUTER_API_KEY": f"sk-or-v1-{os.environ['OPENROUTER_API_KEY']}",
87
- "OPENAI_API_KEY": f"sk-or-v1-{os.environ['OPENAI_API_KEY']}",
88
  }
89
 
90
  api_keys = get_api_keys()
@@ -545,18 +545,27 @@ async def text_to_speech_v2(request: AudioAPI.TTSRequest, api_key: str = Depends
545
  Requires API Key authentication via X-API-Key header.
546
  """
547
  try:
548
- response = openai_client.audio.speech.create(
549
- model=request.model,
550
- voice=request.voice,
551
- input=request.input,
552
- response_format=request.output_format
553
- )
 
 
 
 
 
 
 
 
 
554
 
555
- content_type = f"audio/{request.output_format.value}"
556
- if request.output_format == OpenaiTTSModels.OutputFormat.pcm:
557
- content_type = "audio/pcm"
558
 
559
- return StreamingResponse(io.BytesIO(response.content), media_type=content_type)
560
 
561
  except Exception as e:
562
  raise HTTPException(status_code=500, detail=str(e))
 
84
  logger.info("Loading API keys")
85
  return {
86
  "OPENROUTER_API_KEY": f"sk-or-v1-{os.environ['OPENROUTER_API_KEY']}",
87
+ # "OPENAI_API_KEY": f"sk-or-v1-{os.environ['OPENAI_API_KEY']}",
88
  }
89
 
90
  api_keys = get_api_keys()
 
545
  Requires API Key authentication via X-API-Key header.
546
  """
547
  try:
548
+ response = openai_client.audio.speech.create(
549
+ model=request.model,
550
+ voice=request.voice,
551
+ input=request.input,
552
+ response_format="mp3" # Always set to MP3
553
+ )
554
+
555
+ return StreamingResponse(io.BytesIO(response.content), media_type="audio/mp3")
556
+ # try:
557
+ # response = openai_client.audio.speech.create(
558
+ # model=request.model,
559
+ # voice=request.voice,
560
+ # input=request.input,
561
+ # response_format=request.output_format
562
+ # )
563
 
564
+ # content_type = f"audio/{request.output_format.value}"
565
+ # if request.output_format == OpenaiTTSModels.OutputFormat.pcm:
566
+ # content_type = "audio/pcm"
567
 
568
+ # return StreamingResponse(io.BytesIO(response.content), media_type=content_type)
569
 
570
  except Exception as e:
571
  raise HTTPException(status_code=500, detail=str(e))