Skip to content

Commit 753f1e8

Browse files
authored
Merge branch 'master' into master
2 parents fae97a5 + 68014a5 commit 753f1e8

File tree

13 files changed

+787
-39
lines changed

13 files changed

+787
-39
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
.DS_Store

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2017 Integrated Digital Media, NYU
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 77 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,32 @@
1-
# p5.js-speech
1+
# [p5.speech](https://idmnyu.github.io/p5.js-speech/)
22
Web Audio Speech Synthesis and Speech Recognition Implementation for p5.js (http://p5js.org)
33

44
R. Luke DuBois ([email protected])
5-
[ABILITY Lab](http://abilitylab.nyu.edu) / [Brooklyn Experimental Media Center](http://bxmc.poly.edu)
5+
[ABILITY Project](http://ability.nyu.edu) / [Integrated Design & Media](http://idm.engineering.nyu.edu)
66
NYU
77

8-
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.
99

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).
1111

12-
## Simple Example (Synthesis)
12+
## Download
13+
* [Library only](https://raw.githubusercontent.com/IDMNYU/p5.js-speech/master/lib/p5.speech.js)
14+
15+
## Include from a CDN
16+
```
17+
<script src="https://cdn.jsdelivr.net/gh/IDMNYU/[email protected]/lib/p5.speech.js"></script>
18+
```
19+
20+
## Examples
21+
22+
### Simple Example (Synthesis)
1323
```
14-
var foo = new P5.Speech(); // speech synthesis object
24+
var foo = new p5.Speech(); // speech synthesis object
1525
foo.speak('hi there'); // say something
1626
```
17-
## Simple Example (Recognition)
27+
### Simple Example (Recognition)
1828
```
19-
var foo = new P5.SpeechRec(); // speech recognition object (will prompt for mic access)
29+
var foo = new p5.SpeechRec(); // speech recognition object (will prompt for mic access)
2030
foo.onResult = showResult; // bind callback function to trigger when speech is recognized
2131
foo.start(); // start listening
2232
@@ -25,3 +35,62 @@ function showResult()
2535
console.log(foo.resultString); // log the result
2636
}
2737
```
38+
### More Examples
39+
40+
* [p5.Speech() Simple](https://idmnyu.github.io/p5.js-speech/examples/01simple.html) [(source)](https://github.com/IDMNYU/p5.js-speech/blob/master/examples/01simple.html)
41+
* [p5.Speech() Speech Box](https://idmnyu.github.io/p5.js-speech/examples/02speechbox.html) [(source)](https://github.com/IDMNYU/p5.js-speech/blob/master/examples/02speechbox.html)
42+
* [p5.Speech() Callbacks](https://idmnyu.github.io/p5.js-speech/examples/03callbacks.html) [(source)](https://github.com/IDMNYU/p5.js-speech/blob/master/examples/03callbacks.html)
43+
* [p5.SpeechRec() Simple](https://idmnyu.github.io/p5.js-speech/examples/04simplerecognition.html) [(source)](https://github.com/IDMNYU/p5.js-speech/blob/master/examples/04simplerecognition.html)
44+
* [p5.SpeechRec() Continuous](https://idmnyu.github.io/p5.js-speech/examples/05continuousrecognition.html) [(source)](https://github.com/IDMNYU/p5.js-speech/blob/master/examples/05continuousrecognition.html)
45+
46+
## Reference
47+
48+
### p5.Speech
49+
50+
*constructor*
51+
* **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).
96+

_config.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
theme: jekyll-theme-minimal
2+
title: p5.speech
3+
description: Speech synthesis and recognition for p5.js
4+
show_downloads: "true"

_layouts/default.html

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<!doctype html>
2+
<html lang="{{ site.lang | default: "en-US" }}">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="X-UA-Compatible" content="chrome=1">
6+
7+
{% seo %}
8+
9+
<link rel="stylesheet" href="{{ '/assets/css/style.css?v=' | append: site.github.build_revision | relative_url }}">
10+
<meta name="viewport" content="width=device-width">
11+
<!--[if lt IE 9]>
12+
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
13+
<![endif]-->
14+
</head>
15+
<body>
16+
<style>
17+
a {color:darkred;}
18+
</style>
19+
<div class="wrapper">
20+
<header>
21+
<a href="{{ site.github.url }}"> <h1>{{ site.title | default: site.github.repository_name }}</h1> </a>
22+
<p>{{ site.description | default: site.github.project_tagline }}</p>
23+
24+
{% if site.github.is_project_page %}
25+
<p class="view"><a href="{{ site.github.repository_url }}">View the Project on GitHub <small>{{ github_name }}</small></a></p>
26+
{% endif %}
27+
28+
{% if site.github.is_user_page %}
29+
<p class="view"><a href="{{ site.github.owner_url }}">View My GitHub Profile</a></p>
30+
{% endif %}
31+
32+
{% if site.show_downloads %}
33+
<ul>
34+
<li><a href="{{ site.github.zip_url }}">Download <strong>ZIP File</strong></a></li>
35+
<li><a href="{{ site.github.tar_url }}">Download <strong>TAR Ball</strong></a></li>
36+
<li><a href="{{ site.github.repository_url }}">View On <strong>GitHub</strong></a></li>
37+
</ul>
38+
{% endif %}
39+
<a href="#download">Download</a><br>
40+
<a href="#examples">Examples</a><br>
41+
<a href="#reference">Reference</a><br>
42+
</header>
43+
<section>
44+
45+
{{ content }}
46+
47+
</section>
48+
<footer>
49+
{% if site.github.is_project_page %}
50+
<p>This project is maintained by <a href="https://idmnyu.github.io">{{ site.github.owner_name }}</a>
51+
<a href="http://idm.engineering.nyu.edu" target="_new"><img src="https://github.com/IDMNYU/assets/raw/master/IDM.png" width=250 alt="IDM logo"></a></p>
52+
{% endif %}
53+
<p><small>Hosted on GitHub Pages &mdash; Theme by <a href="https://github.com/orderedlist">orderedlist</a></small></p>
54+
</footer>
55+
</div>
56+
<script src="{{ '/assets/js/scale.fix.js' | relative_url }}"></script>
57+
58+
59+
{% if site.google_analytics %}
60+
<script>
61+
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
62+
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
63+
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
64+
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
65+
66+
ga('create', '{{ site.google_analytics }}', 'auto');
67+
ga('send', 'pageview');
68+
</script>
69+
{% endif %}
70+
</body>
71+
</html>

examples/01simple.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
listbutton.mousePressed(doList);
2929

3030
// say hello:
31-
myVoice.speak('yeah, baby!!!');
31+
myVoice.speak('testing one two three!!!');
3232

3333
}
3434

examples/02speechbox.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
function setup()
1414
{
1515
// input dialog:
16-
input = createInput("yeah, baby!!!");
16+
input = createInput("testing one two three!!!");
1717
input.style("width", 400);
1818
input.position(20, 65);
1919
// checkbox:

examples/03callbacks.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
function speechLoaded()
4545
{
4646
// say cheers:
47-
myVoice.speak("yeah, baby!!!");
47+
myVoice.speak("testing one two three!!!");
4848
}
4949

5050
function speechStarted()

examples/socketexample/index.html

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<html>
2+
<head>
3+
<meta http-equiv="refresh" content="300">
4+
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.4.5/p5.min.js"></script>
5+
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.4.5/addons/p5.dom.js"></script>
6+
<script src="p5.speech.js"></script>
7+
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.4/socket.io.js"></script>
8+
<script>
9+
10+
var myRec = new p5.SpeechRec('en-US', parseResult); // new P5.SpeechRec object
11+
myRec.continuous = true; // do continuous recognition
12+
myRec.interimResults = true; // allow partial recognition (faster, less accurate)
13+
14+
var x, y;
15+
var dx, dy;
16+
17+
var socket;
18+
19+
function setup()
20+
{
21+
// graphics stuff:
22+
createCanvas(800, 600);
23+
background(255, 255, 255);
24+
25+
// instructions:
26+
textSize(48);
27+
textAlign(CENTER);
28+
29+
myRec.start(); // start engine
30+
31+
// client-side socket.io:
32+
socket = io();
33+
34+
noLoop();
35+
}
36+
37+
function draw()
38+
{
39+
40+
}
41+
42+
function parseResult()
43+
{
44+
// recognition system will often append words into phrases.
45+
var res = myRec.resultString;
46+
background(255);
47+
text(res, width/2, height/2);
48+
socket.emit('result', { 'word': res });
49+
}
50+
51+
</script>
52+
</head>
53+
<body>
54+
</body>
55+
</html>

0 commit comments

Comments
 (0)