Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle OpenAI /audio/speech route #500

Closed

Conversation

narengogi
Copy link
Collaborator

@narengogi narengogi commented Aug 12, 2024

Description:

  • Added new route and handler for /audio/speech

Related Issues:

Testing Done

  • Generated audio in all the supported formats for /audio/speech
  • Error Response Handling for /audio/speech
  • Verified that the response stream is sent as is
client = OpenAI(
    base_url="http://localhost:8787/v1",
    api_key="",
    default_headers=createHeaders(
        provider="openai",
    )
)

response = client.audio.with_streaming_response.speech.create(
    model="tts-1",
    voice="alloy",
    input=(
        "Once upon a time, in a quaint village nestled among rolling hills, there lived a curious young girl named Lily. "
        "She had always dreamed of adventure beyond the confines of her small town. One day, while exploring the attic "
        "of her grandmother's old house, Lily discovered a dusty, leather-bound book with strange symbols on its cover. "
        "As she opened it, a swirl of glittering dust escaped, and she found herself transported to a magical realm "
        "filled with talking animals, floating islands, and shimmering forests. Lily embarked on an epic journey, "
        "making friends with a wise owl, a mischievous fox, and a brave knight along the way. Together, they faced "
        "challenges, solved riddles, and ultimately saved the magical realm from an evil sorcerer who sought to plunge "
        "it into eternal darkness. Through her adventures, Lily learned the value of friendship, courage, and the power "
        "of believing in oneself. When she finally returned home, Lily realized that the greatest adventures often begin "
        "with a single step into the unknown, and that magic exists everywhere if you know where to look. "
        "As the years passed, Lily grew older, but she never forgot her magical adventure. She became a storyteller, "
        "sharing tales of wonder and imagination with children in her village. Her stories inspired a new generation "
        "of dreamers and adventurers, each eager to find their own magical realms. And though she never found that "
        "mysterious book again, Lily knew that the real magic had always been within her heart, waiting to be discovered."
    ),
)

with response as streaming_response:
    streaming_response.stream_to_file("output.mp3")

TODO

  • Test .pcm format in /audio/speech route
used `ffplay  -autoexit -f s16le  ~/Documents/generated-speech/fox.pcm` to play file

@narengogi narengogi changed the title Handle OpenAI Audio Routes Handle OpenAI /audio/speech route Aug 12, 2024
@narengogi narengogi marked this pull request as ready for review August 12, 2024 08:05
@VisargD VisargD self-requested a review August 22, 2024 10:09

return tryTargetsResponse;
} catch (err: any) {
console.log('chatCompletion error', err.message);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix this log

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

speech handler should also be added for azure-openai

@narengogi
Copy link
Collaborator Author

Changes now in #538

@narengogi narengogi closed this Aug 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants