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

Added serverless API #282

Closed
wants to merge 7 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added doc string
  • Loading branch information
milo157 committed Oct 22, 2024
commit ed7919a7631ac61ce100640fd7c25e785160bbf5
32 changes: 29 additions & 3 deletions examples/serverless-api/main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,36 @@

import edge_tts
"""
This module provides a serverless API for text-to-speech conversion using Edge TTS.

It includes functionality to generate audio and subtitles from input text,
utilizing the edge_tts library. The main function, `run`, is designed to be
used in a serverless environment, returning an asynchronous generator that
yields audio data and subtitles.

Dependencies:
- edge_tts: For text-to-speech conversion
- typing: For type hinting

Usage:
The main entry point is the `run` function, which takes text input
and an optional voice parameter to generate audio and subtitles.
"""

from typing import Dict
from typing import AsyncGenerator
import edge_tts

async def run(text: str, voice: str = "en-GB-SoniaNeural") -> AsyncGenerator[Dict[str, str], None]:

"""
Asynchronously generates audio and subtitles for the given text using the specified voice.

Args:
text (str): The text to be converted to speech.
voice (str): The voice model to use, defaults to "en-GB-SoniaNeural".

Returns:
AsyncGenerator[Dict[str, str], None]: A generator that yields dictionaries containing
"""
communicate = edge_tts.Communicate(text, voice)
submaker = edge_tts.SubMaker()
audio_data = bytearray()
Expand All @@ -20,4 +46,4 @@ async def run(text: str, voice: str = "en-GB-SoniaNeural") -> AsyncGenerator[Dic
yield {
"audio_data": audio_data.decode("latin-1"),
"subtitles": subtitles
}
}
Loading