TTS
- pipecat.services.neuphonic.tts.language_to_neuphonic_lang_code(language)[source]
- Parameters:
language (Language)
- Return type:
str | None
- class pipecat.services.neuphonic.tts.NeuphonicTTSService(*, api_key, voice_id=None, url='wss://api.neuphonic.com', sample_rate=22050, encoding='pcm_linear', params=None, **kwargs)[source]
Bases:
InterruptibleTTSService
- Parameters:
api_key (str)
voice_id (str | None)
url (str)
sample_rate (int | None)
encoding (str)
params (InputParams | None)
- class InputParams(*, language=Language.EN, speed=1.0)[source]
Bases:
BaseModel
- Parameters:
language (Language | None)
speed (float | None)
- language: Language | None
- speed: float | None
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- can_generate_metrics()[source]
- Return type:
bool
- language_to_service_language(language)[source]
Convert a language to the service-specific language format.
- Parameters:
language (Language) – The language to convert.
- Returns:
The service-specific language identifier, or None if not supported.
- Return type:
str | None
- async start(frame)[source]
Start the TTS service.
- Parameters:
frame (StartFrame) – The start frame containing initialization parameters.
- async stop(frame)[source]
Stop the TTS service.
- Parameters:
frame (EndFrame) – The end frame.
- async cancel(frame)[source]
Cancel the TTS service.
- Parameters:
frame (CancelFrame) – The cancel frame.
- async flush_audio()[source]
Flush any buffered audio data.
- async push_frame(frame, direction=FrameDirection.DOWNSTREAM)[source]
Push a frame downstream with TTS-specific handling.
- Parameters:
frame (Frame) – The frame to push.
direction (FrameDirection) – The direction to push the frame.
- async process_frame(frame, direction)[source]
Process frames with bot speaking state tracking.
- Parameters:
frame (Frame) – The frame to process.
direction (FrameDirection) – The direction of frame processing.
- async run_tts(text)[source]
Run text-to-speech synthesis on the provided text.
This method must be implemented by subclasses to provide actual TTS functionality.
- Parameters:
text (str) – The text to synthesize into speech.
- Yields:
Frame – Audio frames containing the synthesized speech.
- Return type:
AsyncGenerator[Frame, None]
- class pipecat.services.neuphonic.tts.NeuphonicHttpTTSService(*, api_key, voice_id=None, url='https://api.neuphonic.com', sample_rate=22050, encoding='pcm_linear', params=None, **kwargs)[source]
Bases:
TTSService
Neuphonic Text-to-Speech service using HTTP streaming.
- Parameters:
api_key (str) – Neuphonic API key
voice_id (str | None) – ID of the voice to use
url (str) – Base URL for the Neuphonic API (default: “https://api.neuphonic.com”)
sample_rate (int | None) – Sample rate for audio output (default: 22050Hz)
encoding (str) – Audio encoding format (default: “pcm_linear”)
params (InputParams | None) – Additional parameters for TTS generation including language and speed
**kwargs – Additional keyword arguments passed to the parent class
- class InputParams(*, language=Language.EN, speed=1.0)[source]
Bases:
BaseModel
- Parameters:
language (Language | None)
speed (float | None)
- language: Language | None
- speed: float | None
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- can_generate_metrics()[source]
- Return type:
bool
- async start(frame)[source]
Start the TTS service.
- Parameters:
frame (StartFrame) – The start frame containing initialization parameters.
- async flush_audio()[source]
Flush any buffered audio data.
- async run_tts(text)[source]
Generate speech from text using Neuphonic streaming API.
- Parameters:
text (str) – The text to convert to speech
- Yields:
Frames containing audio data and status information
- Return type:
AsyncGenerator[Frame, None]