tts

Neuphonic text-to-speech service implementations.

This module provides WebSocket and HTTP-based integrations with Neuphonic’s text-to-speech API for real-time audio synthesis.

pipecat.services.neuphonic.tts.language_to_neuphonic_lang_code(language: Language) str | None[source]

Convert a Language enum to Neuphonic language code.

Parameters:

language – The Language enum value to convert.

Returns:

The corresponding Neuphonic language code, or None if not supported.

class pipecat.services.neuphonic.tts.NeuphonicTTSSettings(model: str | None | _NotGiven = <factory>, extra: dict[str, ~typing.Any]=<factory>, voice: str | None | _NotGiven = <factory>, language: Language | str | None | _NotGiven = <factory>, speed: float | _NotGiven = <factory>)[source]

Bases: TTSSettings

Settings for NeuphonicTTSService and NeuphonicHttpTTSService.

Parameters:

speed – Speech speed multiplier. Defaults to 1.0.

speed: float | _NotGiven
class pipecat.services.neuphonic.tts.NeuphonicTTSService(*, api_key: str, voice_id: str | None = None, url: str = 'wss://api.neuphonic.com', sample_rate: int | None = 22050, encoding: str = 'pcm_linear', params: InputParams | None = None, settings: NeuphonicTTSSettings | None = None, aggregate_sentences: bool | None = None, text_aggregation_mode: TextAggregationMode | None = None, **kwargs)[source]

Bases: InterruptibleTTSService

Neuphonic real-time text-to-speech service using WebSocket streaming.

Provides real-time text-to-speech synthesis using Neuphonic’s WebSocket API. Supports interruption handling, keepalive connections, and configurable voice parameters for high-quality speech generation.

Settings

alias of NeuphonicTTSSettings

class InputParams(*, language: Language | None = Language.EN, speed: float | None = 1.0)[source]

Bases: BaseModel

Input parameters for Neuphonic TTS configuration.

Deprecated since version 0.0.105: Use settings=NeuphonicTTSService.Settings(...) instead.

Parameters:
  • language – Language for synthesis. Defaults to English.

  • speed – Speech speed multiplier. Defaults to 1.0.

language: Language | None
speed: float | None
__init__(*, api_key: str, voice_id: str | None = None, url: str = 'wss://api.neuphonic.com', sample_rate: int | None = 22050, encoding: str = 'pcm_linear', params: InputParams | None = None, settings: NeuphonicTTSSettings | None = None, aggregate_sentences: bool | None = None, text_aggregation_mode: TextAggregationMode | None = None, **kwargs)[source]

Initialize the Neuphonic TTS service.

Parameters:
  • api_key – Neuphonic API key for authentication.

  • voice_id

    ID of the voice to use for synthesis.

    Deprecated since version 0.0.105: Use settings=NeuphonicTTSService.Settings(voice=...) instead.

  • url – WebSocket URL for the Neuphonic API.

  • sample_rate – Audio sample rate in Hz. Defaults to 22050.

  • encoding – Audio encoding format. Defaults to “pcm_linear”.

  • params

    Additional input parameters for TTS configuration.

    Deprecated since version 0.0.105: Use settings=NeuphonicTTSService.Settings(...) instead.

  • settings – Runtime-updatable settings. When provided alongside deprecated parameters, settings values take precedence.

  • aggregate_sentences

    Deprecated. Use text_aggregation_mode instead.

    Deprecated since version 0.0.104: Use text_aggregation_mode instead.

  • text_aggregation_mode – How to aggregate text before synthesis.

  • **kwargs – Additional arguments passed to parent InterruptibleTTSService.

can_generate_metrics() bool[source]

Check if this service can generate processing metrics.

Returns:

True, as Neuphonic service supports metrics generation.

language_to_service_language(language: Language) str | None[source]

Convert a Language enum to Neuphonic service language format.

Parameters:

language – The language to convert.

Returns:

The Neuphonic-specific language code, or None if not supported.

async start(frame: StartFrame)[source]

Start the Neuphonic TTS service.

Parameters:

frame – The start frame containing initialization parameters.

async stop(frame: EndFrame)[source]

Stop the Neuphonic TTS service.

Parameters:

frame – The end frame.

async cancel(frame: CancelFrame)[source]

Cancel the Neuphonic TTS service.

Parameters:

frame – The cancel frame.

async flush_audio(context_id: str | None = None)[source]

Flush any pending audio synthesis by sending stop command.

async run_tts(text: str, context_id: str) AsyncGenerator[Frame | None, None][source]

Generate speech from text using Neuphonic’s streaming API.

Parameters:
  • text – The text to synthesize into speech.

  • context_id – Unique identifier for this TTS context.

Yields:

Frame – Audio frames containing the synthesized speech.

class pipecat.services.neuphonic.tts.NeuphonicHttpTTSService(*, api_key: str, voice_id: str | None = None, aiohttp_session: ClientSession, url: str = 'https://api.neuphonic.com', sample_rate: int | None = 22050, encoding: str | None = 'pcm_linear', params: InputParams | None = None, settings: NeuphonicTTSSettings | None = None, **kwargs)[source]

Bases: TTSService

Neuphonic text-to-speech service using HTTP streaming.

Provides text-to-speech synthesis using Neuphonic’s HTTP API with server-sent events for streaming audio delivery. Suitable for applications that prefer HTTP-based communication over WebSocket connections.

Settings

alias of NeuphonicTTSSettings

class InputParams(*, language: Language | None = Language.EN, speed: float | None = 1.0)[source]

Bases: BaseModel

Input parameters for Neuphonic HTTP TTS configuration.

Deprecated since version 0.0.105: Use settings=NeuphonicHttpTTSService.Settings(...) instead.

Parameters:
  • language – Language for synthesis. Defaults to English.

  • speed – Speech speed multiplier. Defaults to 1.0.

language: Language | None
speed: float | None
__init__(*, api_key: str, voice_id: str | None = None, aiohttp_session: ClientSession, url: str = 'https://api.neuphonic.com', sample_rate: int | None = 22050, encoding: str | None = 'pcm_linear', params: InputParams | None = None, settings: NeuphonicTTSSettings | None = None, **kwargs)[source]

Initialize the Neuphonic HTTP TTS service.

Parameters:
  • api_key – Neuphonic API key for authentication.

  • voice_id

    ID of the voice to use for synthesis.

    Deprecated since version 0.0.105: Use settings=NeuphonicHttpTTSService.Settings(voice=...) instead.

  • aiohttp_session – Shared aiohttp session for HTTP requests.

  • url – Base URL for the Neuphonic HTTP API.

  • sample_rate – Audio sample rate in Hz. Defaults to 22050.

  • encoding – Audio encoding format. Defaults to “pcm_linear”.

  • params

    Additional input parameters for TTS configuration.

    Deprecated since version 0.0.105: Use settings=NeuphonicHttpTTSService.Settings(...) instead.

  • settings – Runtime-updatable settings. When provided alongside deprecated parameters, settings values take precedence.

  • **kwargs – Additional arguments passed to parent TTSService.

can_generate_metrics() bool[source]

Check if this service can generate processing metrics.

Returns:

True, as Neuphonic HTTP service supports metrics generation.

language_to_service_language(language: Language) str | None[source]

Convert a Language enum to Neuphonic service language format.

Parameters:

language – The language to convert.

Returns:

The Neuphonic-specific language code, or None if not supported.

async start(frame: StartFrame)[source]

Start the Neuphonic HTTP TTS service.

Parameters:

frame – The start frame containing initialization parameters.

async flush_audio(context_id: str | None = None)[source]

Flush any pending audio synthesis.

Note

HTTP-based service doesn’t require explicit flushing.

async run_tts(text: str, context_id: str) AsyncGenerator[Frame | None, None][source]

Generate speech from text using Neuphonic streaming API.

Parameters:
  • text – The text to convert to speech.

  • context_id – Unique identifier for this TTS context.

Yields:

Frame – Audio frames containing the synthesized speech and status information.