File tree Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -211,10 +211,24 @@ def openai_speech() -> Response:
211211 if error :
212212 return jsonify ({"error" : error }), status_code
213213
214+ # Determine content type from validation or default
215+ validated_content_type = "audio/mpeg" # Default
216+ if 'response_format' in body :
217+ format_mapping = {
218+ 'mp3' : 'audio/mpeg' ,
219+ 'opus' : 'audio/opus' ,
220+ 'aac' : 'audio/aac' ,
221+ 'flac' : 'audio/flac' ,
222+ 'wav' : 'audio/wav' ,
223+ 'pcm' : 'audio/pcm'
224+ }
225+ requested_format = body ['response_format' ].lower ()
226+ if requested_format in format_mapping :
227+ validated_content_type = format_mapping [requested_format ]
228+
214229 # Create task data
215230 task_data = {
216231 'data' : openai_fm_data ,
217- 'content_type' : "audio/mpeg" , # Default content type
218232 'timestamp' : datetime .now ().isoformat ()
219233 }
220234
@@ -230,7 +244,7 @@ def openai_speech() -> Response:
230244
231245 return Response (
232246 audio_data ,
233- mimetype = task_data [ 'content_type' ]
247+ mimetype = validated_content_type # Use the correctly determined content type
234248 )
235249 except TimeoutError :
236250 logger .error (f"Task timeout: { task .id } " )
You can’t perform that action at this time.
0 commit comments