Speech

class terminusgps.aws.speech.AsyncSpeechSynthesisManager(bucket_name: str | None = None, region_name: str = 'us-east-1')[source]

Public Data Attributes:

region_name

An AWS region name.

bucket_name

The AWS bucket that will host audio files.

Public Methods:

__init__([bucket_name, region_name])

__aenter__()

Creates an asyncronous session and client.

__aexit__(exc_type, exc_val, exc_tb)

Destroys the asyncronous session.

synthesize_speech(message[, format, ...])

Synthesizes the message into an audio file and saves it to the S3 bucket.

synthesize_speech_batch(messages[, format, ...])

Synthesizes a sequence of messages into audio files and saves them to the S3 bucket.


property bucket_name: str

The AWS bucket that will host audio files.

Type:

str

property region_name: str

An AWS region name.

Type:

str

async synthesize_speech(message: str, format: str = 'ogg_vorbis', sample_rate: int = 22050, language_code: str = 'en-US') None[source]

Synthesizes the message into an audio file and saves it to the S3 bucket.

Parameters:
  • message (str) – A message to be read aloud.

  • format (str) – A file format. Default is "ogg_vorbis".

  • sample_rate (int) – The audio frequency in Hz. Default is 22050.

  • language_code (str) – The language to use in the synthesis. Default is "en-US".

Returns:

The audio file URI.

Return type:

str

async synthesize_speech_batch(messages: Sequence[str], format: str = 'ogg_vorbis', sample_rate: int = 22050, language_code: str = 'en-US') None[source]

Synthesizes a sequence of messages into audio files and saves them to the S3 bucket.

Parameters:
  • messages (Sequence) – A sequence of messages to be read aloud.

  • format (str) – A file format. Default is "ogg_vorbis".

  • sample_rate (int) – The audio frequency in Hz. Default is 22050.

  • language_code (str) – The language to use in the synthesis. Default is "en-US".

Returns:

A list of audio file URIs.

Return type:

list

Usage

import asyncio

from terminusgps.aws.speech import AsyncSpeechSynthesisManager

async def main() -> None:
    async with AsyncSpeechSynthesisManager("my-bucket-name") as manager:
        message: str = "This message should be read aloud and saved as a file in an S3 bucket."
        await manager.synthesize_speech(message)

if __name__ == "__main__":
    asyncio.run(main())