You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a simple p5 extension to provide Web Speech (Synthesis and Recognition) API functionality. It consists of two object classes (p5.Speech and p5.SpeechRec) along with accessor functions to speak and listen for text, change parameters (synthesis voices, recognition models, etc.), and retrieve callbacks from the system.
8
+
**p5.speech** is a simple p5 extension to provide Web Speech (Synthesis and Recognition) API functionality. It consists of two object classes (p5.Speech and p5.SpeechRec) along with accessor functions to speak and listen for text, change parameters (synthesis voices, recognition models, etc.), and retrieve callbacks from the system.
9
9
10
-
Speech recognition requires launching from a server (e.g. a python simpleserver on a local machine).
10
+
Speech recognition requires launching from a server using HTTPS (e.g. using a python server on a local machine... a 'file' URI won't work).
***default_voice**: optional argument to set the default synthesizer voice by number (see *listVoices()*) or by name.
52
+
53
+
*methods*
54
+
***cancel()**: silently cancels the current utterance and clears any queued utterances.
55
+
***listVoices()**: debugging statement. Lists available synthesis voices to the JavaScript console.
56
+
***pause()**: pause the current utterance. The *onPause()* callback will fire.
57
+
***resume()**: resumes the current utterance. The *onResume()* callback will fire.
58
+
***setLang(language)**: sets the language interpreter for the synthesizer voice. Argument is BCP-47; Default is 'en-US'.
59
+
***setPitch(pitch)**: sets playback pitch of synthesized speech from 0.01 (very low) to 2.0 (very high). Default is 1.0; not supported by all browser / OS combinations.
60
+
***setRate(rate)**: sets rate of speech production from 0.1 (very slow) to 2.0 (very fast). Default is 1.0; not supported by all browser / OS combinations.
61
+
***setVoice(voice)**: sets synthesizer voice by number (see listVoices()) or by name; equivalent to the default_voice parameter passed with the constructor.
62
+
***setVolume(volume)**: sets synthesizer volume in the range of 0.0 (silent) to 1.0 (default=max volume).
63
+
***speak(utterance)**: instructs the synthesizer to speak the string encoded in utterance. Depending on the interrupt property, additional calls to *speak()* will queue after or interrupt speech actively being synthesized. When synthesis begins, the *onStart()* callback will fire; when synthesis ends, the *onEnd()* callback will fire.
64
+
***stop()**: stops the current utterance. The *onEnd()* callback will fire.
65
+
66
+
*properties*
67
+
***interrupt**: boolean to set whether the *speak()* method will interrupt (true) or queue after (false = default) existing speech currently being synthesized.
68
+
***onEnd**: function sets callback to fire when an utterance is finished.
69
+
***onLoad**: function sets callback to fire when synthesis voices are loaded.
70
+
***onPause**: function sets callback to fire when an utterance is paused.
71
+
***onResume**: function sets callback to fire when an utterance is resumed.
72
+
***onStart**: function sets callback to fire when synthesis is begun.
73
+
74
+
### p5.SpeechRec
75
+
76
+
*constructor*
77
+
***default_language**: optional argument to set the default BCP-47 language / region to for the speech recognition system.
78
+
* n.b. p5.SpeechRec() won't work unless using a secure (HTTPS) server. if you never get a prompt from the browser to allow access to your microphone, that should be the first thing you troubleshoot.
79
+
80
+
*methods*
81
+
***start()**: instructs the speech recognition system to begin listening. use continuous mode rather than multiple calls to *start()* for multiple recognition tokens within the same site.
82
+
83
+
*properties*
84
+
***continuous**: boolean to set whether the speech recognition engine will give results continuously (true) or just once (false = default).
85
+
***p.s. *continuous* is set to 'false' by default to protect your users' privacy: setting continuous to 'true' creates a persistent open mic between your users' browsing device and the cloud-based speech recognition engine for their browser (i.e. Google).**
86
+
* p.p.s. as an aside, besides being potentially a bad call from an ethical standpoint, *continous* mode is unreliable - the audio pipe between the browser and the recognition server breaks pretty easily, especially with non-Chrome browsers. if you really want something that will continuously recognize speech, set a meta-refresh on your page to reload every couple of minutes.
87
+
***interimResults**: boolean to set whether the speech recognition engine will give faster, partial results (true) or wait for the speaker to pause (false = default).
88
+
***onEnd**: function sets callback to fire when speech recognition ends.
89
+
***onError**: function sets callback to fire when an error occurs on the client side in recording and transmitting the speech.
90
+
***onResult**: function sets callback to fire when synthesis engine has reported a result.
91
+
***onStart**: function sets callback to fire when speech recognition has begun.
92
+
***resultConfidence**: float value (0.0-1.0) representing the confidence level of the speech synthesizer that resultString is what was actually spoken by the user.
93
+
***resultJSON**: JSON object containing a full set of data returned by the speech recognition system.
94
+
***resultString**: String containing the most recently detected speech.
95
+
***resultValue**: boolean value containing a status flag reported by the server (true = speech successfully recognized).
0 commit comments