tts.openai#

Description#

This plugin provides an interface to the OpenAI text-to-speech API.

It requires the platypush.plugins.openai.OpenaiPlugin plugin to be configured.

param kwargs:

Extra arguments to be passed to the TtsPlugin constructor, including output_device and output_volume. output_device accepts a PortAudio/sounddevice device index, PortAudio/sounddevice device name, or PulseAudio/PipeWire sink name (requires pactl). output_volume is a playback volume percentage.

Configuration#

tts.openai:
  # [Optional]
  # Model to be used for the text-to-speech conversion.
  # See the `OpenAI API models documentation
  # <https://platform.openai.com/docs/models/tts>`_ for the list of
  # available models (default: ``tts-1``).
  # model: tts-1  # type=str

  # [Optional]
  # Default voice to be used. See the `OpenAI API
  # voices documentation
  # <https://platform.openai.com/docs/guides/text-to-speech/voice-options>`_
  # for the list of available voices (default: ``nova``).
  # voice: nova  # type=str

  # [Optional]
  # Default timeout for the API requests (default: 10s).
  # timeout: 10  # type=float

  # [Optional]
  # Language code (default: ``en-US``).
  # language: en-US

  # [Optional]
  # Audio output device to use for playback.
  # Supported formats: PortAudio/sounddevice device index,
  # PortAudio/sounddevice device name, or PulseAudio/PipeWire sink name
  # (e.g. ``alsa_output.pci-...``; requires ``pactl``). If specified,
  # it is passed as the ``device`` argument to
  # `SoundPlugin.play <https://docs.platypush.tech/platypush/plugins/sound.html#platypush.plugins.sound.SoundPlugin.play>`_.
  # output_device:   # type=int | str | None

  # [Optional]
  # Playback volume, as a percentage. ``100`` means
  # unchanged, values below ``100`` attenuate, and values above ``100``
  # amplify with clipping in the playback path. It is passed as the
  # ``volume`` argument to `SoundPlugin.play <https://docs.platypush.tech/platypush/plugins/sound.html#platypush.plugins.sound.SoundPlugin.play>`_.
  # output_volume:   # type=float | None

Dependencies#

pip

pip install numpy sounddevice

Alpine

apk add py3-numpy portaudio-dev ffmpeg

Debian

apt install portaudio19-dev python3-numpy ffmpeg

Fedora

yum install python-numpy portaudio-devel ffmpeg

Arch Linux

pacman -S portaudio python-numpy ffmpeg python-sounddevice

Actions#

Module reference#

class platypush.plugins.tts.openai.TtsOpenaiPlugin(model: str = 'tts-1', voice: str = 'nova', timeout: float = 10, **kwargs)[source]#

Bases: TtsPlugin

This plugin provides an interface to the OpenAI text-to-speech API.

It requires the platypush.plugins.openai.OpenaiPlugin plugin to be configured.

__init__(model: str = 'tts-1', voice: str = 'nova', timeout: float = 10, **kwargs)[source]#
Parameters:
  • model – Model to be used for the text-to-speech conversion. See the OpenAI API models documentation for the list of available models (default: tts-1).

  • voice – Default voice to be used. See the OpenAI API voices documentation for the list of available voices (default: nova).

  • timeout – Default timeout for the API requests (default: 10s).

  • kwargs – Extra arguments to be passed to the platypush.plugins.tts.TtsPlugin constructor, including output_device and output_volume. output_device accepts a PortAudio/sounddevice device index, PortAudio/sounddevice device name, or PulseAudio/PipeWire sink name (requires pactl). output_volume is a playback volume percentage.

say(text: str, *_, model: str | None = None, voice: str | None = None, **player_args)[source]#

Say some text.

Parameters:
  • text – Text to say.

  • model – Default model override.

  • voice – Default voice override.

  • player_args – Extends the additional arguments to be passed to platypush.plugins.sound.SoundPlugin.play() (like volume, duration, channels etc.).

stop()[source]#

Stop the playback.