Movatterモバイル変換


[0]ホーム

URL:


Skip to content

OpenAI TTS

OpenAITTSModel

Bases:TTSModel

A text-to-speech model for OpenAI.

Source code insrc/agents/voice/models/openai_tts.py
classOpenAITTSModel(TTSModel):"""A text-to-speech model for OpenAI."""def__init__(self,model:str,openai_client:AsyncOpenAI,):"""Create a new OpenAI text-to-speech model.        Args:            model: The name of the model to use.            openai_client: The OpenAI client to use.        """self.model=modelself._client=openai_client@propertydefmodel_name(self)->str:returnself.modelasyncdefrun(self,text:str,settings:TTSModelSettings)->AsyncIterator[bytes]:"""Run the text-to-speech model.        Args:            text: The text to convert to speech.            settings: The settings to use for the text-to-speech model.        Returns:            An iterator of audio chunks.        """response=self._client.audio.speech.with_streaming_response.create(model=self.model,voice=settings.voiceorDEFAULT_VOICE,input=text,response_format="pcm",extra_body={"instructions":settings.instructions,},)asyncwithresponseasstream:asyncforchunkinstream.iter_bytes(chunk_size=1024):yieldchunk

__init__

__init__(model:str,openai_client:AsyncOpenAI)

Create a new OpenAI text-to-speech model.

Parameters:

NameTypeDescriptionDefault
modelstr

The name of the model to use.

required
openai_clientAsyncOpenAI

The OpenAI client to use.

required
Source code insrc/agents/voice/models/openai_tts.py
def__init__(self,model:str,openai_client:AsyncOpenAI,):"""Create a new OpenAI text-to-speech model.    Args:        model: The name of the model to use.        openai_client: The OpenAI client to use.    """self.model=modelself._client=openai_client

runasync

run(text:str,settings:TTSModelSettings)->AsyncIterator[bytes]

Run the text-to-speech model.

Parameters:

NameTypeDescriptionDefault
textstr

The text to convert to speech.

required
settingsTTSModelSettings

The settings to use for the text-to-speech model.

required

Returns:

TypeDescription
AsyncIterator[bytes]

An iterator of audio chunks.

Source code insrc/agents/voice/models/openai_tts.py
asyncdefrun(self,text:str,settings:TTSModelSettings)->AsyncIterator[bytes]:"""Run the text-to-speech model.    Args:        text: The text to convert to speech.        settings: The settings to use for the text-to-speech model.    Returns:        An iterator of audio chunks.    """response=self._client.audio.speech.with_streaming_response.create(model=self.model,voice=settings.voiceorDEFAULT_VOICE,input=text,response_format="pcm",extra_body={"instructions":settings.instructions,},)asyncwithresponseasstream:asyncforchunkinstream.iter_bytes(chunk_size=1024):yieldchunk

[8]ページ先頭

©2009-2025 Movatter.jp