p5-phone 1.6.4 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +268 -4
- package/dist/p5-phone.js +533 -42
- package/dist/p5-phone.min.js +2 -2
- package/examples/Phone Sensor Examples/microphone/01_mic_level/index.html +2 -2
- package/examples/Phone Sensor Examples/microphone/02_speech_recognition/README.md +25 -29
- package/examples/Phone Sensor Examples/microphone/02_speech_recognition/index.html +2 -2
- package/examples/Phone Sensor Examples/movement/01_orientation_basic/index.html +2 -2
- package/examples/Phone Sensor Examples/movement/02_rotational_velocity/index.html +2 -2
- package/examples/Phone Sensor Examples/movement/03_acceleration/index.html +2 -2
- package/examples/Phone Sensor Examples/sound/01_dual_audio/index.html +1 -1
- package/examples/Phone Sensor Examples/sound/02_volume_touches/index.html +1 -1
- package/examples/Phone Sensor Examples/touch/01_touch_basic/index.html +1 -1
- package/examples/Phone Sensor Examples/touch/02_touch_zones/index.html +1 -1
- package/examples/Phone Sensor Examples/touch/03_touch_count/index.html +1 -1
- package/examples/Phone Sensor Examples/touch/04_touch_distance/index.html +1 -1
- package/examples/Phone Sensor Examples/touch/05_touch_angle/index.html +1 -1
- package/examples/Phone Sensor Examples/vibration/01_haptic_feedback/index.html +1 -1
- package/examples/Phone Sensor Examples - Minimal/microphone/01_mic_level/index.html +3 -3
- package/examples/Phone Sensor Examples - Minimal/movement/01_orientation_basic/index.html +2 -2
- package/examples/Phone Sensor Examples - Minimal/movement/02_rotational_velocity/index.html +2 -2
- package/examples/Phone Sensor Examples - Minimal/movement/03_acceleration/index.html +2 -2
- package/examples/Phone Sensor Examples - Minimal/sound/01_sound_basic/index.html +3 -3
- package/examples/Phone Sensor Examples - Minimal/sound/02_sound_amplitude/index.html +3 -3
- package/examples/Phone Sensor Examples - Minimal/touch/01_touch_basic/index.html +2 -2
- package/examples/Phone Sensor Examples - Minimal/touch/02_touch_zones/index.html +2 -2
- package/examples/Phone Sensor Examples - Minimal/touch/03_touch_count/index.html +2 -2
- package/examples/Phone Sensor Examples - Minimal/touch/04_touch_distance/index.html +2 -2
- package/examples/Phone Sensor Examples - Minimal/touch/05_touch_angle/index.html +2 -2
- package/examples/Phone Sensor Examples - Minimal/vibration/01_haptic_feedback/index.html +2 -2
- package/examples/Phone and Gif/collision/index.html +2 -2
- package/examples/Phone and Gif/fetch/index.html +2 -2
- package/examples/Phone and Gif/fly/index.html +2 -2
- package/examples/Phone and Gif/roll/index.html +2 -2
- package/examples/UIStyles/banner-style/index.html +16 -0
- package/examples/UIStyles/banner-style/sketch.js +35 -0
- package/examples/UIStyles/canvas-style/index.html +16 -0
- package/examples/UIStyles/canvas-style/sketch.js +26 -0
- package/examples/UIStyles/custom-element/index.html +32 -0
- package/examples/UIStyles/custom-element/sketch.js +35 -0
- package/examples/UXcompare/button-vs-movement/index.html +2 -2
- package/examples/UXcompare/button-vs-orientation/index.html +2 -2
- package/examples/UXcompare/button-vs-shake/index.html +2 -2
- package/examples/UXcompare/gyroscope-demo/index.html +2 -2
- package/examples/UXcompare/microphone-demo/index.html +3 -3
- package/examples/UXcompare/slider-vs-angle/index.html +2 -2
- package/examples/UXcompare/slider-vs-distance/index.html +2 -2
- package/examples/UXcompare/slider-vs-microphone/index.html +3 -3
- package/examples/UXcompare/slider-vs-touches/index.html +2 -2
- package/examples/UXcompare/sliders-vs-acceleration/index.html +2 -2
- package/examples/UXcompare/sliders-vs-rotation/index.html +2 -2
- package/examples/blankTemplate/index.html +2 -2
- package/examples/homepage/index.html +37 -9
- package/examples/ml5/Gaze_detector_class/index.html +1 -1
- package/examples/ml5/PHONE_BodyPose_two_points/index.html +1 -1
- package/examples/ml5/PHONE_FaceMesh_two_points/index.html +1 -1
- package/examples/ml5/PHONE_HandPose_two_points/index.html +1 -1
- package/package.json +1 -1
- package/src/p5-phone.js +533 -42
package/README.md
CHANGED
|
@@ -60,17 +60,27 @@ This library simplifies access to the following p5.js mobile sensor and audio co
|
|
|
60
60
|
- [Motion Sensor Activation](#motion-sensor-activation)
|
|
61
61
|
- [Microphone Activation](#microphone-activation)
|
|
62
62
|
- [Sound Output Activation](#sound-output-activation)
|
|
63
|
+
- [Speech Recognition Activation](#speech-recognition-activation)
|
|
64
|
+
- [Combined Activation](#combined-activation)
|
|
63
65
|
- [Vibration Motor (Android Only)](#vibration-motor-android-only)
|
|
66
|
+
- [PhoneCamera (ML5 Integration)](#phonecamera-ml5-integration)
|
|
64
67
|
- [Debug System](#debug-system)
|
|
68
|
+
- [Permission UI Styles](#permission-ui-styles)
|
|
69
|
+
- [Tap (Full-Screen Overlay)](#tap-full-screen-overlay)
|
|
70
|
+
- [Button (Centered Button)](#button-centered-button)
|
|
71
|
+
- [Canvas (First Touch)](#canvas-first-touch)
|
|
72
|
+
- [Banner (Top/Bottom Bar)](#banner-topbottom-bar)
|
|
73
|
+
- [Custom Element Binding](#custom-element-binding)
|
|
74
|
+
- [Troubleshooting / FAQ](#troubleshooting--faq)
|
|
65
75
|
|
|
66
76
|
### CDN (Recommended)
|
|
67
77
|
|
|
68
78
|
```html
|
|
69
79
|
<!-- Minified version (recommended) -->
|
|
70
|
-
<script src="https://cdn.jsdelivr.net/npm/p5-phone@1.
|
|
80
|
+
<script src="https://cdn.jsdelivr.net/npm/p5-phone@1.7.0/dist/p5-phone.min.js"></script>
|
|
71
81
|
|
|
72
82
|
<!-- Development version (larger, with comments) -->
|
|
73
|
-
<!-- <script src="https://cdn.jsdelivr.net/npm/p5-phone@1.
|
|
83
|
+
<!-- <script src="https://cdn.jsdelivr.net/npm/p5-phone@1.7.0/dist/p5-phone.js"></script> -->
|
|
74
84
|
```
|
|
75
85
|
|
|
76
86
|
### Basic Setup
|
|
@@ -98,7 +108,7 @@ This library simplifies access to the following p5.js mobile sensor and audio co
|
|
|
98
108
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.11.10/p5.min.js"></script>
|
|
99
109
|
|
|
100
110
|
<!-- Load p5-phone library -->
|
|
101
|
-
<script src="https://cdn.jsdelivr.net/npm/p5-phone@1.
|
|
111
|
+
<script src="https://cdn.jsdelivr.net/npm/p5-phone@1.7.0/dist/p5-phone.min.js"></script>
|
|
102
112
|
|
|
103
113
|
</head>
|
|
104
114
|
<body>
|
|
@@ -192,19 +202,51 @@ enableMicButton(text) // Button-based microphone activation
|
|
|
192
202
|
enableSoundTap(message) // Tap anywhere to enable sound playback
|
|
193
203
|
enableSoundButton(text) // Button-based sound activation
|
|
194
204
|
|
|
205
|
+
// Speech recognition activation (Web Speech API)
|
|
206
|
+
enableSpeechTap(message) // Tap anywhere to enable speech
|
|
207
|
+
enableSpeechButton(text) // Button-based speech activation
|
|
208
|
+
|
|
209
|
+
// Combined activation (motion + microphone)
|
|
210
|
+
enableAllTap(message) // Tap anywhere to enable both
|
|
211
|
+
enableAllButton(text) // Button-based combined activation
|
|
212
|
+
|
|
195
213
|
// Vibration motor (Android only)
|
|
196
214
|
enableVibrationTap(message) // Tap anywhere to enable vibration
|
|
197
215
|
enableVibrationButton(text) // Button-based vibration activation
|
|
198
216
|
vibrate(pattern) // Trigger vibration (duration or pattern array)
|
|
199
217
|
stopVibration() // Stop any ongoing vibration
|
|
200
218
|
|
|
219
|
+
// Camera (ML5 integration)
|
|
220
|
+
createPhoneCamera(active, mirror, mode) // Create camera instance
|
|
221
|
+
enableCameraTap(message) // Tap to enable camera
|
|
222
|
+
enableCameraButton(text) // Button-based camera activation
|
|
223
|
+
|
|
224
|
+
// --- Alternative Permission UI Styles (v1.7.0) ---
|
|
225
|
+
|
|
226
|
+
// Canvas-first-touch — permissions fire on first canvas interaction
|
|
227
|
+
enableGyroCanvas(message) // Also: enableMicCanvas, enableSoundCanvas,
|
|
228
|
+
// enableSpeechCanvas, enableVibrationCanvas,
|
|
229
|
+
// enableAllCanvas, enableCameraCanvas
|
|
230
|
+
|
|
231
|
+
// Banner — slim notification bar at top or bottom of screen
|
|
232
|
+
enableGyroBanner(message, position) // position: 'top' or 'bottom'
|
|
233
|
+
// Also: enableMicBanner, enableSoundBanner,
|
|
234
|
+
// enableSpeechBanner, enableVibrationBanner,
|
|
235
|
+
// enableAllBanner, enableCameraBanner
|
|
236
|
+
|
|
237
|
+
// Custom element binding — attach to your own DOM element
|
|
238
|
+
enableGyroOn(selector) // e.g., enableGyroOn('#my-button')
|
|
239
|
+
// Also: enableMicOn, enableSoundOn, enableSpeechOn,
|
|
240
|
+
// enableVibrationOn, enableAllOn, enableCameraOn
|
|
241
|
+
|
|
201
242
|
// Status variables (check these in your code)
|
|
202
243
|
window.sensorsEnabled // Boolean: true when motion sensors are active
|
|
203
244
|
window.micEnabled // Boolean: true when microphone is active
|
|
204
245
|
window.soundEnabled // Boolean: true when sound output is active
|
|
246
|
+
window.speechEnabled // Boolean: true when speech recognition is active
|
|
205
247
|
window.vibrationEnabled // Boolean: true when vibration is available (Android only)
|
|
206
248
|
|
|
207
|
-
// Debug system
|
|
249
|
+
// Debug system
|
|
208
250
|
showDebug() // Show on-screen debug panel with automatic error catching
|
|
209
251
|
hideDebug() // Hide debug panel
|
|
210
252
|
toggleDebug() // Toggle panel visibility
|
|
@@ -233,6 +275,7 @@ this.enableGyroTap('Tap to start');
|
|
|
233
275
|
- `window.sensorsEnabled` - Boolean indicating if motion sensors are active
|
|
234
276
|
- `window.micEnabled` - Boolean indicating if microphone is active
|
|
235
277
|
- `window.soundEnabled` - Boolean indicating if sound output is active
|
|
278
|
+
- `window.speechEnabled` - Boolean indicating if speech recognition is active
|
|
236
279
|
- `window.vibrationEnabled` - Boolean indicating if vibration is available (Android only)
|
|
237
280
|
|
|
238
281
|
**Usage:**
|
|
@@ -570,6 +613,80 @@ function gameOver() {
|
|
|
570
613
|
- Don't overuse - vibration can quickly drain battery
|
|
571
614
|
- Test on Android devices as iOS doesn't support vibration
|
|
572
615
|
|
|
616
|
+
### Speech Recognition Activation
|
|
617
|
+
|
|
618
|
+
**Purpose:** Enable the Web Speech API for voice input and speech-to-text in mobile browsers.
|
|
619
|
+
|
|
620
|
+
**Important:** This does NOT create a `p5.AudioIn` object — it only activates the audio context needed for the Web Speech API. You must create your own `p5.SpeechRec` object after enabling.
|
|
621
|
+
|
|
622
|
+
**Commands:**
|
|
623
|
+
- `enableSpeechTap(message)` - Tap anywhere on screen to enable speech recognition
|
|
624
|
+
- `enableSpeechButton(text)` - Creates a button with custom text to enable speech
|
|
625
|
+
|
|
626
|
+
**Usage:**
|
|
627
|
+
```javascript
|
|
628
|
+
let speechRec;
|
|
629
|
+
|
|
630
|
+
function setup() {
|
|
631
|
+
createCanvas(windowWidth, windowHeight);
|
|
632
|
+
|
|
633
|
+
// Enable speech recognition
|
|
634
|
+
enableSpeechTap('Tap to enable speech recognition');
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
// Use userSetupComplete() to know when permissions are ready
|
|
638
|
+
function userSetupComplete() {
|
|
639
|
+
if (window.speechEnabled) {
|
|
640
|
+
speechRec = new p5.SpeechRec('en-US');
|
|
641
|
+
speechRec.continuous = true;
|
|
642
|
+
speechRec.interimResults = true;
|
|
643
|
+
speechRec.onResult = gotSpeech;
|
|
644
|
+
speechRec.start();
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
function gotSpeech() {
|
|
649
|
+
if (speechRec.resultValue) {
|
|
650
|
+
debug('You said:', speechRec.resultString);
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
```
|
|
654
|
+
|
|
655
|
+
### Combined Activation
|
|
656
|
+
|
|
657
|
+
**Purpose:** Enable both motion sensors and microphone with a single permission prompt, reducing the number of taps required.
|
|
658
|
+
|
|
659
|
+
**Commands:**
|
|
660
|
+
- `enableAllTap(message)` - Tap anywhere to enable motion sensors + microphone
|
|
661
|
+
- `enableAllButton(text)` - Button-based combined activation
|
|
662
|
+
|
|
663
|
+
**Usage:**
|
|
664
|
+
```javascript
|
|
665
|
+
let mic;
|
|
666
|
+
|
|
667
|
+
function setup() {
|
|
668
|
+
createCanvas(windowWidth, windowHeight);
|
|
669
|
+
mic = new p5.AudioIn();
|
|
670
|
+
lockGestures();
|
|
671
|
+
|
|
672
|
+
// One tap enables both sensors and microphone
|
|
673
|
+
enableAllTap('Tap to enable sensors & microphone');
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
function draw() {
|
|
677
|
+
background(220);
|
|
678
|
+
|
|
679
|
+
if (window.sensorsEnabled) {
|
|
680
|
+
circle(width/2 + rotationY * 3, height/2 + rotationX * 3, 50);
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
if (window.micEnabled) {
|
|
684
|
+
let level = mic.getLevel();
|
|
685
|
+
rect(10, 10, level * 200, 20);
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
```
|
|
689
|
+
|
|
573
690
|
### PhoneCamera (ML5 Integration)
|
|
574
691
|
|
|
575
692
|
**Purpose:** Simplified camera access optimized for ML5.js machine learning models (FaceMesh, HandPose, BodyPose, etc.). Handles camera initialization, coordinate mapping, mirroring, and display modes automatically.
|
|
@@ -768,4 +885,151 @@ debug("Touch points:", touches);
|
|
|
768
885
|
debug({rotation: rotationX, acceleration: accelerationX});
|
|
769
886
|
```
|
|
770
887
|
|
|
888
|
+
---
|
|
889
|
+
|
|
890
|
+
## Permission UI Styles
|
|
891
|
+
|
|
892
|
+
Beyond the default **Tap** and **Button** styles, p5-phone v1.7.0 provides three additional ways to present permission prompts. Each permission type (sensors, microphone, speech, all, camera) has all five variants.
|
|
893
|
+
|
|
894
|
+
### Canvas Style
|
|
895
|
+
|
|
896
|
+
The canvas displays a centered message until the user taps. Great for "full-screen tap to start" experiences where you want the canvas to feel like a splash screen.
|
|
897
|
+
|
|
898
|
+
**Commands:**
|
|
899
|
+
- `enableSensorCanvas(message)`
|
|
900
|
+
- `enableMicCanvas(message)`
|
|
901
|
+
- `enableSpeechCanvas(message)`
|
|
902
|
+
- `enableAllCanvas(message)`
|
|
903
|
+
- `enableCameraCanvas(message)`
|
|
904
|
+
|
|
905
|
+
**Usage:**
|
|
906
|
+
```javascript
|
|
907
|
+
function setup() {
|
|
908
|
+
createCanvas(windowWidth, windowHeight);
|
|
909
|
+
lockGestures();
|
|
910
|
+
enableSensorCanvas('Tap canvas to begin');
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
function draw() {
|
|
914
|
+
if (!window.sensorsEnabled) return;
|
|
915
|
+
background(220);
|
|
916
|
+
circle(width/2 + rotationY * 3, height/2 + rotationX * 3, 50);
|
|
917
|
+
}
|
|
918
|
+
```
|
|
919
|
+
|
|
920
|
+
### Banner Style
|
|
921
|
+
|
|
922
|
+
A styled banner slides in from the top of the screen with an animated entrance. After the user taps, the banner slides away and permissions are activated. Ideal when you want to keep your canvas visible underneath the prompt.
|
|
923
|
+
|
|
924
|
+
**Commands:**
|
|
925
|
+
- `enableSensorBanner(message)`
|
|
926
|
+
- `enableMicBanner(message)`
|
|
927
|
+
- `enableSpeechBanner(message)`
|
|
928
|
+
- `enableAllBanner(message)`
|
|
929
|
+
- `enableCameraBanner(message)`
|
|
930
|
+
|
|
931
|
+
**Usage:**
|
|
932
|
+
```javascript
|
|
933
|
+
function setup() {
|
|
934
|
+
createCanvas(windowWidth, windowHeight);
|
|
935
|
+
lockGestures();
|
|
936
|
+
enableSensorBanner('Tap here to enable motion sensors');
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
function draw() {
|
|
940
|
+
background(220);
|
|
941
|
+
if (window.sensorsEnabled) {
|
|
942
|
+
text('Rotation: ' + rotationX.toFixed(1), 20, 60);
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
```
|
|
946
|
+
|
|
947
|
+
### Custom Element Style
|
|
948
|
+
|
|
949
|
+
Bind the permission activation to any existing HTML element on the page using a CSS selector. This gives you full control over the look and placement of the trigger. The element is hidden after successful activation.
|
|
950
|
+
|
|
951
|
+
**Commands:**
|
|
952
|
+
- `enableSensorOn(selector)`
|
|
953
|
+
- `enableMicOn(selector)`
|
|
954
|
+
- `enableSpeechOn(selector)`
|
|
955
|
+
- `enableAllOn(selector)`
|
|
956
|
+
- `enableCameraOn(selector)`
|
|
957
|
+
|
|
958
|
+
**Usage (HTML):**
|
|
959
|
+
```html
|
|
960
|
+
<button id="start-btn" style="font-size:24px; padding:20px;">
|
|
961
|
+
Start Experience
|
|
962
|
+
</button>
|
|
963
|
+
```
|
|
964
|
+
|
|
965
|
+
**Usage (sketch.js):**
|
|
966
|
+
```javascript
|
|
967
|
+
function setup() {
|
|
968
|
+
createCanvas(windowWidth, windowHeight);
|
|
969
|
+
lockGestures();
|
|
970
|
+
enableAllOn('#start-btn');
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
function draw() {
|
|
974
|
+
if (!window.sensorsEnabled) return;
|
|
975
|
+
background(220);
|
|
976
|
+
circle(width/2 + rotationY * 3, height/2 + rotationX * 3, 50);
|
|
977
|
+
}
|
|
978
|
+
```
|
|
979
|
+
|
|
980
|
+
### Which Style Should I Use?
|
|
981
|
+
|
|
982
|
+
| Style | Best For | How It Works |
|
|
983
|
+
|-------|----------|-------------|
|
|
984
|
+
| **Tap** | Quick prototypes | Full-screen transparent overlay |
|
|
985
|
+
| **Button** | Clear UI | Auto-generated styled button |
|
|
986
|
+
| **Canvas** | Splash screens | Message drawn on the p5 canvas |
|
|
987
|
+
| **Banner** | Polished apps | Animated slide-in banner |
|
|
988
|
+
| **Custom** | Custom designs | Bind to your own HTML element |
|
|
989
|
+
|
|
990
|
+
---
|
|
991
|
+
|
|
992
|
+
## Troubleshooting / FAQ
|
|
993
|
+
|
|
994
|
+
### Why do I have to tap before sensors work?
|
|
995
|
+
|
|
996
|
+
iOS Safari requires a **user gesture** (tap, click) before granting access to motion sensors and the microphone. This is a browser security requirement — it cannot be bypassed. Android does not have this restriction, but the tap/button still works on Android (it's a no-op).
|
|
997
|
+
|
|
998
|
+
### My sketch works on desktop but not on my phone
|
|
999
|
+
|
|
1000
|
+
1. Make sure you're serving over **HTTPS** — motion sensors and microphone are blocked on insecure origins.
|
|
1001
|
+
2. Check that you've called one of the `enable...` functions in `setup()`.
|
|
1002
|
+
3. On iOS, check Settings → Safari → Motion & Orientation Access is enabled.
|
|
1003
|
+
|
|
1004
|
+
### The debug console isn't showing
|
|
1005
|
+
|
|
1006
|
+
Make sure you're calling `enableConsole()` in your sketch. The console overlay appears at the bottom of the screen. You can use `debug()`, `debugWarn()`, and `debugError()` to log to it.
|
|
1007
|
+
|
|
1008
|
+
### How do I know when permissions are ready?
|
|
1009
|
+
|
|
1010
|
+
Define a `userSetupComplete()` function — it's called automatically after the user taps and all requested permissions have been granted:
|
|
1011
|
+
|
|
1012
|
+
```javascript
|
|
1013
|
+
function userSetupComplete() {
|
|
1014
|
+
debug('All permissions granted!');
|
|
1015
|
+
debug('Sensors:', window.sensorsEnabled);
|
|
1016
|
+
debug('Mic:', window.micEnabled);
|
|
1017
|
+
}
|
|
1018
|
+
```
|
|
1019
|
+
|
|
1020
|
+
You can also check the status variables at any time:
|
|
1021
|
+
- `window.sensorsEnabled`
|
|
1022
|
+
- `window.micEnabled`
|
|
1023
|
+
- `window.speechEnabled`
|
|
1024
|
+
|
|
1025
|
+
### Camera feed is blank or not loading
|
|
1026
|
+
|
|
1027
|
+
1. Ensure your page is served over **HTTPS**.
|
|
1028
|
+
2. Check that you're using `new PhoneCamera(this)` in your sketch.
|
|
1029
|
+
3. Grant camera permission in the browser when prompted.
|
|
1030
|
+
4. Some iOS versions require the user to explicitly allow camera access in Settings → Safari → Camera.
|
|
1031
|
+
|
|
1032
|
+
### Vibration isn't working on iOS
|
|
1033
|
+
|
|
1034
|
+
The Vibration API is **not supported on iOS**. Use `navigator.vibrate` only as an enhancement for Android devices. Check `'vibrate' in navigator` before calling it.
|
|
771
1035
|
|