easy-scratch/doc/scratch-vm/Scratch3Text2SpeechBlocks.html

2763 lines
92 KiB
HTML
Raw Normal View History

2025-02-12 12:27:32 +00:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Scratch3Text2SpeechBlocks - Documentation</title>
<script src="scripts/prettify/prettify.js"></script>
<script src="scripts/prettify/lang-css.js"></script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
<script src="scripts/nav.js" defer></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
<div class="navicon"></div>
</label>
<label for="nav-trigger" class="overlay"></label>
<nav >
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="-_StackFrame.html">_StackFrame</a><ul class='methods'><li data-type='method'><a href="-_StackFrame.html#.create">create</a></li><li data-type='method'><a href="-_StackFrame.html#.release">release</a></li><li data-type='method'><a href="-_StackFrame.html#reset">reset</a></li><li data-type='method'><a href="-_StackFrame.html#reuse">reuse</a></li></ul></li><li><a href="BLE.html">BLE</a><ul class='methods'><li data-type='method'><a href="BLE.html#connectPeripheral">connectPeripheral</a></li><li data-type='method'><a href="BLE.html#didReceiveCall">didReceiveCall</a></li><li data-type='method'><a href="BLE.html#disconnect">disconnect</a></li><li data-type='method'><a href="BLE.html#handleDisconnectError">handleDisconnectError</a></li><li data-type='method'><a href="BLE.html#isConnected">isConnected</a></li><li data-type='method'><a href="BLE.html#read">read</a></li><li data-type='method'><a href="BLE.html#requestPeripheral">requestPeripheral</a></li><li data-type='method'><a href="BLE.html#startNotifications">startNotifications</a></li><li data-type='method'><a href="BLE.html#write">write</a></li></ul></li><li><a href="BlockCached.html">BlockCached</a></li><li><a href="Blocks.html">Blocks</a><ul class='methods'><li data-type='method'><a href="Blocks.html#_addScript">_addScript</a></li><li data-type='method'><a href="Blocks.html#_deleteScript">_deleteScript</a></li><li data-type='method'><a href="Blocks.html#_getBackdropField">_getBackdropField</a></li><li data-type='method'><a href="Blocks.html#_getBlockParams">_getBlockParams</a></li><li data-type='method'><a href="Blocks.html#_getCostumeField">_getCostumeField</a></li><li data-type='method'><a href="Blocks.html#_getCustomBlockInternal">_getCustomBlockInternal</a></li><li data-type='method'><a href="Blocks.html#_getSoundField">_getSoundField</a></li><li data-type='method'><a href="Blocks.html#_getSpriteField">_getSpriteField</a></li><li data-type='method'><a href="Blocks.html#blocklyListen">blocklyListen</a></li><li data-type='method'><a href="Blocks.html#blockToXML">blockToXML</a></li><li data-type='method'><a href="Blocks.html#changeBlock">changeBlock</a></li><li data-type='method'><a href="Blocks.html#createBlock">createBlock</a></li><li data-type='method'><a href="Blocks.html#deleteBlock">deleteBlock</a></li><li data-type='method'><a href="Blocks.html#emitProjectChanged">emitProjectChanged</a></li><li data-type='method'><a href="Blocks.html#getAllVariableAndListReferences">getAllVariableAndListReferences</a></li><li data-type='method'><a href="Blocks.html#getBlock">getBlock</a></li><li data-type='method'><a href="Blocks.html#getBranch">getBranch</a></li><li data-type='method'><a href="Blocks.html#getFields">getFields</a></li><li data-type='method'><a href="Blocks.html#getInputs">getInputs</a></li><li data-type='method'><a href="Blocks.html#getMutation">getMutation</a></li><li data-type='method'><a href="Blocks.html#getNextBlock">getNextBlock</a></li><li data-type='method'><a href="Blocks.html#getOpcode">getOpcode</a></li><li data-type='method'><a href="Blocks.html#getProcedureDefinition">getProcedureDefinition</a></li><li data-type='method'><a href="Blocks.html#getProcedureParamNamesAndIds">getProcedureParamNamesAndIds</a></li><li data-type='method'><a href="Blocks.html#getProcedureParamNamesIdsAndDefaults">getProcedureParamNamesIdsAndDefaults</a></li><li data-type='method'><a href="Blocks.html#getScripts">getScripts</a></li><li data-type='method'><a href="Blocks.html#getTopLevelScript">getTopLevelScript</a></li><li data-type='method'><a href="Blocks.html#moveBlock">moveBlock</a></li><li data-type='method'><a href="Blocks.html#mutationToXML">mutationToXML</a></li><li data-type='method'><a href="Blocks.html#resetCache">resetCache</a></li><li data-type='method'><a href="Blocks.html#runAllMonitored">runAllMonitored</a></li><li data-type='method'><a href="Blocks.html#toXML">toXML</a></li><li data-type='method'><a href="Blocks.html#updateAssetName">updateAssetName</a></li><li data-type='method'><a href
</nav>
<div id="main">
<h1 class="page-title">Scratch3Text2SpeechBlocks</h1>
<section>
<header>
<h2>
Scratch3Text2SpeechBlocks
</h2>
<div class="class-description"><p>Class for the text2speech blocks.</p></div>
</header>
<article>
<div class="container-overview">
<h2>Constructor</h2>
<h4 class="name" id="Scratch3Text2SpeechBlocks"><span class="type-signature"></span>new Scratch3Text2SpeechBlocks<span class="signature">()</span><span class="type-signature"></span></h4>
<dl class="details">
</dl>
</div>
<h3 class="subsection-title">Members</h3>
<h4 class="name" id=".DEFAULT_TEXT2SPEECH_STATE"><span class="type-signature">(static) </span>DEFAULT_TEXT2SPEECH_STATE<span class="type-signature"> :Text2SpeechState</span></h4>
<dl class="details">
</dl>
<div class="description">
<p>The default state, to be used when a target has no existing state.</p>
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">Text2SpeechState</span>
</li>
</ul>
<h4 class="name" id=".STATE_KEY"><span class="type-signature">(static) </span>STATE_KEY<span class="type-signature"></span></h4>
<dl class="details">
</dl>
<div class="description">
<p>The key to load &amp; store a target's text2speech state.</p>
</div>
<h4 class="name" id="_soundPlayers"><span class="type-signature"></span>_soundPlayers<span class="type-signature"> :Map.&lt;string, SoundPlayer></span></h4>
<dl class="details">
</dl>
<div class="description">
<p>Map of soundPlayers by sound id.</p>
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">Map.&lt;string, SoundPlayer></span>
</li>
</ul>
<h4 class="name" id="_supportedLocales"><span class="type-signature"></span>_supportedLocales<span class="type-signature"> :Array</span></h4>
<dl class="details">
</dl>
<div class="description">
<p>A list of all Scratch locales that are supported by the extension.</p>
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">Array</span>
</li>
</ul>
<h4 class="name" id="DEFAULT_LANGUAGE"><span class="type-signature"></span>DEFAULT_LANGUAGE<span class="type-signature"> :string</span></h4>
<dl class="details">
</dl>
<div class="description">
<p>A default language to use for speech synthesis.</p>
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">string</span>
</li>
</ul>
<h4 class="name" id="LANGUAGE_INFO"><span class="type-signature"></span>LANGUAGE_INFO<span class="type-signature"></span></h4>
<dl class="details">
</dl>
<div class="description">
<p>An object with information for each language.</p>
<p>A note on the different sets of locales referred to in this extension:</p>
<p>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.</p>
</div>
<h4 class="name" id="runtime"><span class="type-signature"></span>runtime<span class="type-signature"> :<a href="Runtime.html">Runtime</a></span></h4>
<dl class="details">
</dl>
<div class="description">
<p>The runtime instantiating this block package.</p>
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type"><a href="Runtime.html">Runtime</a></span>
</li>
</ul>
<h4 class="name" id="VOICE_INFO"><span class="type-signature"></span>VOICE_INFO<span class="type-signature"></span></h4>
<dl class="details">
</dl>
<div class="description">
<p>An object with info for each voice.</p>
</div>
<h3 class="subsection-title">Methods</h3>
<h4 class="name" id="_getExtensionLocaleForSupportedLocale"><span class="type-signature"></span>_getExtensionLocaleForSupportedLocale<span class="signature">(locale)</span><span class="type-signature"> &rarr; (nullable) {string}</span></h4>
<dl class="details">
</dl>
<div class="description">
<p>Get the extension locale for a supported locale, or null.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>locale</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last"><p>a locale code.</p></td>
</tr>
</tbody>
</table>
<h5>Returns:</h5>
<div class="param-desc">
<p>a locale supported by the extension.</p>
</div>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">string</span>
</dd>
</dl>
<h4 class="name" id="_getSpeechSynthLocale"><span class="type-signature"></span>_getSpeechSynthLocale<span class="signature">()</span><span class="type-signature"> &rarr; {string}</span></h4>
<dl class="details">
</dl>
<div class="description">
<p>Get the locale code used by the speech synthesis server corresponding to
the current language code set for the extension.</p>
</div>
<h5>Returns:</h5>
<div class="param-desc">
<p>a speech synthesis locale.</p>
</div>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">string</span>
</dd>
</dl>
<h4 class="name" id="_getState"><span class="type-signature">(private) </span>_getState<span class="signature">(target)</span><span class="type-signature"> &rarr; {Text2SpeechState}</span></h4>
<dl class="details">
</dl>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>target</code></td>
<td class="type">
<span class="param-type"><a href="Target.html">Target</a></span>
</td>
<td class="description last"><p>collect state for this target.</p></td>
</tr>
</tbody>
</table>
<h5>Returns:</h5>
<div class="param-desc">
<p>the mutable state associated with that target. This will be created if necessary.</p>
</div>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">Text2SpeechState</span>
</dd>
</dl>
<h4 class="name" id="_getSupportedLocales"><span class="type-signature"></span>_getSupportedLocales<span class="signature">()</span><span class="type-signature"> &rarr; {Array}</span></h4>
<dl class="details">
</dl>
<div class="description">
<p>Get an array of the locales supported by this extension.</p>
</div>
<h5>Returns:</h5>
<div class="param-desc">
<p>An array of locale strings.</p>
</div>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">Array</span>
</dd>
</dl>
<h4 class="name" id="_onTargetCreated"><span class="type-signature">(private) </span>_onTargetCreated<span class="signature">(newTarget, sourceTarget<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4>
<dl class="details">
</dl>
<div class="description">
<p>When a Target is cloned, clone the state.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>newTarget</code></td>
<td class="type">
<span class="param-type"><a href="Target.html">Target</a></span>
</td>
<td class="attributes">
</td>
<td class="description last"><p>the newly created target.</p></td>
</tr>
<tr>
<td class="name"><code>sourceTarget</code></td>
<td class="type">
<span class="param-type"><a href="Target.html">Target</a></span>
</td>
<td class="attributes">
&lt;optional><br>
</td>
<td class="description last"><p>the target used as a source for the new clone, if any.</p></td>
</tr>
</tbody>
</table>
<h5>Listens to Events:</h5>
<ul>
<li><a href="Runtime.html#event:targetWasCreated">Runtime#event:targetWasCreated</a></li>
</ul>
<h4 class="name" id="_stopAllSpeech"><span class="type-signature"></span>_stopAllSpeech<span class="signature">()</span><span class="type-signature"></span></h4>
<dl class="details">
</dl>
<div class="description">
<p>Stop all currently playing speech sounds.</p>
</div>
<h4 class="name" id="getCurrentLanguage"><span class="type-signature"></span>getCurrentLanguage<span class="signature">()</span><span class="type-signature"> &rarr; {string}</span></h4>
<dl class="details">
</dl>
<div class="description">
<p>Get the language code currently set for the extension.</p>
</div>
<h5>Returns:</h5>
<div class="param-desc">
<p>a Scratch locale code.</p>
</div>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">string</span>
</dd>
</dl>
<h4 class="name" id="getEditorLanguage"><span class="type-signature"></span>getEditorLanguage<span class="signature">()</span><span class="type-signature"> &rarr; {string}</span></h4>
<dl class="details">
</dl>
<div class="description">
<p>Get the language code currently set in the editor, or fall back to the
browser locale.</p>
</div>
<h5>Returns:</h5>
<div class="param-desc">
<p>a Scratch locale code.</p>
</div>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">string</span>
</dd>
</dl>
<h4 class="name" id="getInfo"><span class="type-signature"></span>getInfo<span class="signature">()</span><span class="type-signature"> &rarr; {object}</span></h4>
<dl class="details">
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<p>metadata for this extension and its blocks.</p>
</div>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">object</span>
</dd>
</dl>
<h4 class="name" id="getLanguageMenu"><span class="type-signature"></span>getLanguageMenu<span class="signature">()</span><span class="type-signature"> &rarr; {array}</span></h4>
<dl class="details">
</dl>
<div class="description">
<p>Get the localized menu of languages for the &quot;set language&quot; 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.</p>
</div>
<h5>Returns:</h5>
<div class="param-desc">
<p>the text and value for each menu item.</p>
</div>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">array</span>
</dd>
</dl>
<h4 class="name" id="getVoiceMenu"><span class="type-signature"></span>getVoiceMenu<span class="signature">()</span><span class="type-signature"> &rarr; {array}</span></h4>
<dl class="details">
</dl>
<div class="description">
<p>Get the menu of voices for the &quot;set voice&quot; block.</p>
</div>
<h5>Returns:</h5>
<div class="param-desc">
<p>the text and value for each menu item.</p>
</div>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">array</span>
</dd>
</dl>
<h4 class="name" id="isSupportedLanguage"><span class="type-signature"></span>isSupportedLanguage<span class="signature">(languageCode)</span><span class="type-signature"> &rarr; {boolean}</span></h4>
<dl class="details">
</dl>
<div class="description">
<p>Check if a Scratch language code is in the list of supported languages for the
speech synthesis service.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>languageCode</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last"><p>the language code to check.</p></td>
</tr>
</tbody>
</table>
<h5>Returns:</h5>
<div class="param-desc">
<p>true if the language code is supported.</p>
</div>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">boolean</span>
</dd>
</dl>
<h4 class="name" id="setCurrentLanguage"><span class="type-signature"></span>setCurrentLanguage<span class="signature">(locale)</span><span class="type-signature"></span></h4>
<dl class="details">
</dl>
<div class="description">
<p>Set the language code for the extension.
It is stored in the stage so it can be saved and loaded with the project.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>locale</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last"><p>a locale code.</p></td>
</tr>
</tbody>
</table>
<h4 class="name" id="setLanguage"><span class="type-signature"></span>setLanguage<span class="signature">(args)</span><span class="type-signature"></span></h4>
<dl class="details">
</dl>
<div class="description">
<p>Set the language for speech synthesis.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>args</code></td>
<td class="type">
<span class="param-type">object</span>
</td>
<td class="description last"><p>Block arguments</p></td>
</tr>
</tbody>
</table>
<h4 class="name" id="setVoice"><span class="type-signature"></span>setVoice<span class="signature">(args, util)</span><span class="type-signature"></span></h4>
<dl class="details">
</dl>
<div class="description">
<p>Set the voice for speech synthesis for this sprite.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>args</code></td>
<td class="type">
<span class="param-type">object</span>
</td>
<td class="description last"><p>Block arguments</p></td>
</tr>
<tr>
<td class="name"><code>util</code></td>
<td class="type">
<span class="param-type">object</span>
</td>
<td class="description last"><p>Utility object provided by the runtime.</p></td>
</tr>
</tbody>
</table>
<h4 class="name" id="speakAndWait"><span class="type-signature"></span>speakAndWait<span class="signature">(args, util)</span><span class="type-signature"> &rarr; {Promise}</span></h4>
<dl class="details">
</dl>
<div class="description">
<p>Convert the provided text into a sound file and then play the file.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>args</code></td>
<td class="type">
<span class="param-type">object</span>
</td>
<td class="description last"><p>Block arguments</p></td>
</tr>
<tr>
<td class="name"><code>util</code></td>
<td class="type">
<span class="param-type">object</span>
</td>
<td class="description last"><p>Utility object provided by the runtime.</p></td>
</tr>
</tbody>
</table>
<h5>Returns:</h5>
<div class="param-desc">
<p>A promise that resolves after playing the sound</p>
</div>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise</span>
</dd>
</dl>
</article>
</section>
</div>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>
<script>prettyPrint();</script>
<script src="scripts/polyfill.js"></script>
<script src="scripts/linenumber.js"></script>
</body>
</html>