Constructor
new Scratch3Text2SpeechBlocks()
Members
(static) DEFAULT_TEXT2SPEECH_STATE :Text2SpeechState
The default state, to be used when a target has no existing state.
Type:
- Text2SpeechState
(static) STATE_KEY
The key to load & store a target's text2speech state.
_soundPlayers :Map.<string, SoundPlayer>
Map of soundPlayers by sound id.
Type:
- Map.<string, SoundPlayer>
_supportedLocales :Array
A list of all Scratch locales that are supported by the extension.
Type:
- Array
DEFAULT_LANGUAGE :string
A default language to use for speech synthesis.
Type:
- string
LANGUAGE_INFO
An object with information for each language.
A note on the different sets of locales referred to in this extension:
SCRATCH LOCALE Set by the editor, and used to store the language state in the project. Listed in l10n: https://github.com/LLK/scratch-l10n/blob/master/src/supported-locales.js SUPPORTED LOCALE A Scratch locale that has a corresponding extension locale. EXTENSION LOCALE A locale corresponding to one of the available spoken languages in the extension. There can be multiple supported locales for a single extension locale. For example, for both written versions of chinese, zh-cn and zh-tw, we use a single spoken language (Mandarin). So there are two supported locales, with a single extension locale. SPEECH SYNTH LOCALE A different locale code system, used by our speech synthesis service. Each extension locale has a speech synth locale.
runtime :Runtime
The runtime instantiating this block package.
Type:
VOICE_INFO
An object with info for each voice.
Methods
_getExtensionLocaleForSupportedLocale(locale) → (nullable) {string}
Get the extension locale for a supported locale, or null.
Parameters:
Name | Type | Description |
---|---|---|
locale |
string | a locale code. |
Returns:
a locale supported by the extension.
- Type
- string
_getSpeechSynthLocale() → {string}
Get the locale code used by the speech synthesis server corresponding to the current language code set for the extension.
Returns:
a speech synthesis locale.
- Type
- string
(private) _getState(target) → {Text2SpeechState}
Parameters:
Name | Type | Description |
---|---|---|
target |
Target | collect state for this target. |
Returns:
the mutable state associated with that target. This will be created if necessary.
- Type
- Text2SpeechState
_getSupportedLocales() → {Array}
Get an array of the locales supported by this extension.
Returns:
An array of locale strings.
- Type
- Array
(private) _onTargetCreated(newTarget, sourceTargetopt)
When a Target is cloned, clone the state.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
newTarget |
Target | the newly created target. |
|
sourceTarget |
Target |
<optional> |
the target used as a source for the new clone, if any. |
Listens to Events:
_stopAllSpeech()
Stop all currently playing speech sounds.
getCurrentLanguage() → {string}
Get the language code currently set for the extension.
Returns:
a Scratch locale code.
- Type
- string
getEditorLanguage() → {string}
Get the language code currently set in the editor, or fall back to the browser locale.
Returns:
a Scratch locale code.
- Type
- string
getInfo() → {object}
Returns:
metadata for this extension and its blocks.
- Type
- object
getLanguageMenu() → {array}
Get the localized menu of languages for the "set language" block. For each language: if there is a custom translated spoken language name, use that; otherwise use the translation in the languageNames menuMap; otherwise fall back to the untranslated name in LANGUAGE_INFO.
Returns:
the text and value for each menu item.
- Type
- array
getVoiceMenu() → {array}
Get the menu of voices for the "set voice" block.
Returns:
the text and value for each menu item.
- Type
- array
isSupportedLanguage(languageCode) → {boolean}
Check if a Scratch language code is in the list of supported languages for the speech synthesis service.
Parameters:
Name | Type | Description |
---|---|---|
languageCode |
string | the language code to check. |
Returns:
true if the language code is supported.
- Type
- boolean
setCurrentLanguage(locale)
Set the language code for the extension. It is stored in the stage so it can be saved and loaded with the project.
Parameters:
Name | Type | Description |
---|---|---|
locale |
string | a locale code. |
setLanguage(args)
Set the language for speech synthesis.
Parameters:
Name | Type | Description |
---|---|---|
args |
object | Block arguments |
setVoice(args, util)
Set the voice for speech synthesis for this sprite.
Parameters:
Name | Type | Description |
---|---|---|
args |
object | Block arguments |
util |
object | Utility object provided by the runtime. |
speakAndWait(args, util) → {Promise}
Convert the provided text into a sound file and then play the file.
Parameters:
Name | Type | Description |
---|---|---|
args |
object | Block arguments |
util |
object | Utility object provided by the runtime. |
Returns:
A promise that resolves after playing the sound
- Type
- Promise