mirror of
https://github.com/remsky/Kokoro-FastAPI.git
synced 2025-04-13 09:39:17 +00:00
fix: download_format option for audio response, handling in create_speech
This commit is contained in:
parent
127aae4fab
commit
37ea01eaf9
3 changed files with 10 additions and 3 deletions
|
@ -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",
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Reference in a new issue