fix: download_format option for audio response, handling in create_speech

This commit is contained in:
remsky 2025-02-13 00:04:21 -07:00
parent 127aae4fab
commit 37ea01eaf9
3 changed files with 10 additions and 3 deletions

View file

@ -197,7 +197,9 @@ async def create_speech(
if request.return_download_link:
from ..services.temp_manager import TempFileWriter
temp_writer = TempFileWriter(request.response_format)
# Use download_format if specified, otherwise use response_format
output_format = request.download_format or request.response_format
temp_writer = TempFileWriter(output_format)
await temp_writer.__aenter__() # Initialize temp file
# Get download path immediately after temp file creation
@ -205,7 +207,7 @@ async def create_speech(
# Create response headers with download path
headers = {
"Content-Disposition": f"attachment; filename=speech.{request.response_format}",
"Content-Disposition": f"attachment; filename=speech.{output_format}",
"X-Accel-Buffering": "no",
"Cache-Control": "no-cache",
"Transfer-Encoding": "chunked",

View file

@ -60,6 +60,10 @@ class OpenAISpeechRequest(BaseModel):
default="mp3",
description="The format to return audio in. Supported formats: mp3, opus, flac, wav, pcm. PCM format returns raw 16-bit samples without headers. AAC is not currently supported.",
)
download_format: Optional[Literal["mp3", "opus", "aac", "flac", "wav", "pcm"]] = Field(
default=None,
description="Optional different format for the final download. If not provided, uses response_format.",
)
speed: float = Field(
default=1.0,
ge=0.25,

View file

@ -39,7 +39,8 @@ export class AudioService {
body: JSON.stringify({
input: text,
voice: voice,
response_format: 'mp3',
response_format: 'mp3', // Always use mp3 for streaming playback
download_format: document.getElementById('format-select').value || 'mp3', // Format for final download
stream: true,
speed: speed,
return_download_link: true,