tts.google#
Description#
Advanced text-to-speech engine that leverages the Google Cloud TTS API. See https://cloud.google.com/text-to-speech/docs/quickstart-client-libraries#client-libraries-install-python for how to enable the API on your account and get your credentials.
- param kwargs:
Extra arguments to be passed to the TtsPlugin constructor, including
output_deviceandoutput_volume.output_deviceaccepts a PortAudio/sounddevice device index, PortAudio/sounddevice device name, or PulseAudio/PipeWire sink name (requirespactl).output_volumeis a playback volume percentage.
Configuration#
tts.google:
# [Optional]
# Language code, see
# https://cloud.google.com/text-to-speech/docs/basics for supported
# languages.
# language: en-US # type=str
# [Optional]
# Voice type, see
# https://cloud.google.com/text-to-speech/docs/basics for supported
# voices.
# voice: # type=str | None
# [Optional]
# Voice gender (MALE, FEMALE or NEUTRAL).
# gender: FEMALE # type=str
# [Optional]
# Where your GCloud credentials for TTS are
# stored, see https://cloud.google.com/text-to-speech/docs/basics.
# credentials_file: ~/.credentials/platypush/google/platypush-tts.json # type=str
# [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 sounddevice numpy google-cloud-texttospeech
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.google.TtsGooglePlugin(language: str = 'en-US', voice: str | None = None, gender: str = 'FEMALE', credentials_file: str = '~/.credentials/platypush/google/platypush-tts.json', **kwargs)[source]#
Bases:
TtsPluginAdvanced text-to-speech engine that leverages the Google Cloud TTS API. See https://cloud.google.com/text-to-speech/docs/quickstart-client-libraries#client-libraries-install-python for how to enable the API on your account and get your credentials.
- __init__(language: str = 'en-US', voice: str | None = None, gender: str = 'FEMALE', credentials_file: str = '~/.credentials/platypush/google/platypush-tts.json', **kwargs)[source]#
- Parameters:
language – Language code, see https://cloud.google.com/text-to-speech/docs/basics for supported languages.
voice – Voice type, see https://cloud.google.com/text-to-speech/docs/basics for supported voices.
gender – Voice gender (MALE, FEMALE or NEUTRAL).
credentials_file – Where your GCloud credentials for TTS are stored, see https://cloud.google.com/text-to-speech/docs/basics.
kwargs – Extra arguments to be passed to the
platypush.plugins.tts.TtsPluginconstructor, includingoutput_deviceandoutput_volume.output_deviceaccepts a PortAudio/sounddevice device index, PortAudio/sounddevice device name, or PulseAudio/PipeWire sink name (requirespactl).output_volumeis a playback volume percentage.
- say(text: str, language: str | None = None, voice: str | None = None, gender: str | None = None, **player_args)[source]#
Say a phrase.
- Parameters:
text – Text to say.
language – Language code override.
voice – Voice type override.
gender – Gender override.
player_args – Extends the additional arguments to be passed to
platypush.plugins.sound.SoundPlugin.play()(like volume, duration, channels etc.).
- stop()#
Stop the playback.