panel.widgets.text_to_speech module#
The Panel TextToSpeak Widget provides functionality for text to speech via the the HTML5 SpeechSynthesis API.
See https://developer.mozilla.org/en-US/docs/Web/API/SpeechSynthesis
The term utterance is used throughout the API. It is the smallest unit of speech in spoken language analysis.
- class panel.widgets.text_to_speech.TextToSpeech(*, _voices, auto_speak, cancel, pause, resume, speak, lang, pitch, rate, voice, volume, disabled, loading, align, aspect_ratio, css_classes, design, height, height_policy, margin, max_height, max_width, min_height, min_width, sizing_mode, styles, stylesheets, tags, visible, width, width_policy, value, name)[source]#
-
The TextToSpeech widget wraps the HTML5 SpeechSynthesis API
See https://developer.mozilla.org/en-US/docs/Web/API/SpeechSynthesis
Reference: https://panel.holoviz.org/reference/widgets/TextToSpeech.html
- Example:
>>> TextToSpeech(name="Speech Synthesis", value="Data apps are nice")
Parameter Definitions
Parameters inherited from:
panel.viewable.Layoutable
: align, aspect_ratio, css_classes, design, min_width, min_height, max_width, max_height, styles, stylesheets, tags, width_policy, height_policy, sizing_mode, visiblepanel.viewable.Viewable
: loadingpanel.widgets.base.Widget
: height, margin, width, disabledpanel.widgets.text_to_speech.Utterance
: value, lang, pitch, rate, voice, volumeauto_speak = Boolean(default=True, label='Auto speak')
Whether or not to automatically speak when the value changes.
cancel = Event(default=False, label='Cancel')
Removes all utterances from the utterance queue.
pause = Event(default=False, label='Pause')
Puts the TextToSpeak object into a paused state.
resume = Event(default=False, label='Resume')
Puts the TextToSpeak object into a non-paused state: resumes it if it was already paused.
paused = Boolean(constant=True, default=False, label='Paused', readonly=True)
A Boolean that returns true if the TextToSpeak object is in a paused state.
pending = Boolean(constant=True, default=False, label='Pending', readonly=True)
A Boolean that returns true if the utterance queue contains as-yet-unspoken utterances.
speak = Event(default=False, label='Speak')
Speak. I.e. send a new Utterance to the browser
speaking = Boolean(constant=True, default=False, label='Speaking', readonly=True)
A Boolean that returns true if an utterance is currently in the process of being spoken — even if TextToSpeak is in a paused state.
voices = List(bounds=(0, None), constant=True, default=[], label='Voices', readonly=True)
Returns a list of Voice objects representing all the available voices on the current device.
_voices = List(bounds=(0, None), default=[], label=' voices')
- class panel.widgets.text_to_speech.Utterance(*, lang, pitch, rate, value, voice, volume, name)[source]#
Bases:
Parameterized
An utterance is the smallest unit of speech in spoken language analysis.
The Utterance Model wraps the HTML5 SpeechSynthesisUtterance API
See https://developer.mozilla.org/en-US/docs/Web/API/SpeechSynthesisUtterance
Methods
set_voices
(voices)Updates the lang and voice parameter objects, default and value
to_dict
([include_uuid])Returns the object parameter values in a dictionary
Parameter Definitions
value = String(default='', label='Value')
The text that will be synthesised when the utterance is spoken. The text may be provided as plain text, or a well-formed SSML document.
lang = Selector(default='', label='Lang', names={}, objects=[''])
The language of the utterance.
pitch = Number(bounds=(0.0, 2.0), default=1.0, inclusive_bounds=(True, True), label='Pitch')
The pitch at which the utterance will be spoken at expressed as a number between 0 and 2.
rate = Number(bounds=(0.1, 10.0), default=1.0, inclusive_bounds=(True, True), label='Rate')
The speed at which the utterance will be spoken at expressed as a number between 0.1 and 10.
voice = Selector(label='Voice', names={}, objects=[])
The voice that will be used to speak the utterance.
volume = Number(bounds=(0.0, 1.0), default=1.0, inclusive_bounds=(True, True), label='Volume')
The volume that the utterance will be spoken at expressed as a number between 0 and 1.
- class panel.widgets.text_to_speech.Voice(*, default, lang, local_service, voice_uri, name)[source]#
Bases:
Parameterized
The current device (i.e. OS and Browser) provides a list of Voices. Each with a unique name and speaking a specific language.
Wraps the HTML5 SpeecSynthesisVoice API
See https://developer.mozilla.org/en-US/docs/Web/API/SpeechSynthesisVoice
Methods
group_by_lang
(voices)Returns a dictionary where the key is the lang and the value is a list of voices for that language.
to_voices_list
(voices)Returns a list of Voice objects from the list of dicts provided
Parameter Definitions
default = Boolean(constant=True, default=False, label='Default')
A Boolean indicating whether the voice is the default voice for the current app language (True), or not (False.)
lang = String(constant=True, default='', label='Lang')
Returns a BCP 47 language tag indicating the language of the voice.
local_service = Boolean(constant=True, default=False, label='Local service')
A Boolean indicating whether the voice is supplied by a local speech synthesizer service (True), or a remote speech synthesizer service (False.)
voice_uri = String(constant=True, default='', label='Voice uri')
Returns the type of URI and location of the speech synthesis service for this voice.