Skip to content

Commit

Permalink
Added doc string
Browse files Browse the repository at this point in the history
  • Loading branch information
milo157 committed Oct 22, 2024
1 parent 1300546 commit ed7919a
Showing 1 changed file with 29 additions and 3 deletions.
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
}
}

0 comments on commit ed7919a

Please sign in to comment.