pxt-common-packages 9.4.1 → 9.4.5

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.
Files changed (65) hide show
  1. package/built/common-sim.d.ts +8 -0
  2. package/built/common-sim.js +74 -0
  3. package/libs/azureiot/built/debug/binary.js +461 -461
  4. package/libs/color/built/debug/binary.js +8 -8
  5. package/libs/color-sensor/built/debug/binary.js +8 -8
  6. package/libs/controller/built/debug/binary.js +7126 -6975
  7. package/libs/controller---none/built/debug/binary.js +7105 -6954
  8. package/libs/core---esp32/pins.cpp +30 -4
  9. package/libs/core---esp32/shims.d.ts +15 -0
  10. package/libs/core---esp32s2/shims.d.ts +15 -0
  11. package/libs/datalogger/built/debug/binary.js +63 -63
  12. package/libs/edge-connector/built/debug/binary.js +8 -8
  13. package/libs/esp32/built/debug/binary.js +462 -462
  14. package/libs/game/_locales/game-jsdoc-strings.json +10 -1
  15. package/libs/game/_locales/game-strings.json +18 -2
  16. package/libs/game/assetTemplates.ts +2 -0
  17. package/libs/game/built/debug/binary.js +7018 -6867
  18. package/libs/game/docs/reference/scene/get-tile-location.md +96 -0
  19. package/libs/game/docs/reference/scene/get-tiles-by-type.md +64 -43
  20. package/libs/game/docs/reference/scene/is-hitting-tile.md +87 -0
  21. package/libs/game/docs/reference/scene/on-hit-wall.md +88 -0
  22. package/libs/game/docs/reference/scene/on-overlap-tile.md +88 -0
  23. package/libs/game/docs/reference/scene/place-on-random-tile.md +95 -41
  24. package/libs/game/docs/reference/scene/place-on-tile.md +88 -0
  25. package/libs/game/docs/reference/scene/set-tile-at.md +45 -41
  26. package/libs/game/docs/reference/scene/set-tilemap.md +89 -0
  27. package/libs/game/docs/reference/scene/set-wall-at.md +86 -0
  28. package/libs/game/docs/reference/scene/tile-at-location-equals.md +97 -0
  29. package/libs/game/docs/reference/scene/tile-kind-at.md +118 -0
  30. package/libs/game/docs/reference/scene.md +20 -16
  31. package/libs/game/docs/reference/sprites/sprite/ax.md +34 -3
  32. package/libs/game/docs/reference/sprites/sprite/ay.md +34 -3
  33. package/libs/game/docs/reference/sprites/sprite/fx.md +123 -0
  34. package/libs/game/docs/reference/sprites/sprite/fy.md +123 -0
  35. package/libs/game/docs/reference/sprites.md +2 -0
  36. package/libs/game/physics.ts +1 -1
  37. package/libs/game/renderText.ts +74 -11
  38. package/libs/game/scenes.ts +5 -1
  39. package/libs/game/sprite.ts +23 -6
  40. package/libs/game/spriteevents.ts +7 -7
  41. package/libs/game/sprites.ts +16 -0
  42. package/libs/game/spritesay.ts +204 -51
  43. package/libs/game/tilemap.ts +173 -27
  44. package/libs/lcd/built/debug/binary.js +8 -8
  45. package/libs/light-spectrum-sensor/built/debug/binary.js +8 -8
  46. package/libs/lora/built/debug/binary.js +8 -8
  47. package/libs/matrix-keypad/built/debug/binary.js +8 -8
  48. package/libs/mqtt/built/debug/binary.js +176 -176
  49. package/libs/net/built/debug/binary.js +176 -176
  50. package/libs/net-game/built/debug/binary.js +8802 -8651
  51. package/libs/palette/built/debug/binary.js +7017 -6866
  52. package/libs/pixel/built/debug/binary.js +8 -8
  53. package/libs/power/built/debug/binary.js +8 -8
  54. package/libs/proximity/built/debug/binary.js +8 -8
  55. package/libs/radio/built/debug/binary.js +8 -8
  56. package/libs/radio-broadcast/built/debug/binary.js +8 -8
  57. package/libs/rotary-encoder/built/debug/binary.js +8 -8
  58. package/libs/screen/built/debug/binary.js +50 -50
  59. package/libs/servo/built/debug/binary.js +8 -8
  60. package/libs/storyboard/built/debug/binary.js +7017 -6866
  61. package/libs/text-to-speech/pxt.json +14 -0
  62. package/libs/text-to-speech/shims.d.ts +47 -0
  63. package/libs/text-to-speech/sim/tts.ts +72 -0
  64. package/libs/text-to-speech/tts.ts +70 -0
  65. package/package.json +1 -1
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "text-to-speech",
3
+ "description": "Browser-only text to speech support",
4
+ "files": [
5
+ "shims.d.ts",
6
+ "tts.ts"
7
+ ],
8
+ "testFiles": [
9
+ ],
10
+ "public": true,
11
+ "dependencies": {
12
+ "core": "file:../core"
13
+ }
14
+ }
@@ -0,0 +1,47 @@
1
+ //% icon="\uf075"
2
+ //% color="#f59c16"
3
+ //% block="Text to Speech"
4
+ declare namespace tts {
5
+ //% shim=tts::_speakAsync promise
6
+ function speak(text: string, pitch?: number, rate?: number, volume?: number, language?: string, onStart?: () => void, onBoundary?: (offset: number, nextWord: string, fullText: string) => void): void;
7
+
8
+ //% shim=tts::_getLanguageCode
9
+ function getLanguageCode(): string;
10
+
11
+ /**
12
+ * Pauses the current text being spoken. Any calls waiting for the text to finish
13
+ * will not return until the text is either resumed or cancelled.
14
+ */
15
+ //% shim=tts::_pause
16
+ //% blockId=tts_pause
17
+ //% block="pause speech"
18
+ //% weight=90
19
+ function pause(): void;
20
+
21
+ /**
22
+ * Returns true if the text to speech is currently paused
23
+ */
24
+ //% shim=tts::_isPaused
25
+ //% blockId=tts_isPaused
26
+ //% block="is speech paused"
27
+ //% weight=60
28
+ function isPaused(): boolean;
29
+
30
+ /**
31
+ * Resumes the current text being spoken if in the paused state.
32
+ */
33
+ //% shim=tts::_resume
34
+ //% blockId=tts_resume
35
+ //% block="resume speech"
36
+ //% weight=80
37
+ function resume(): void;
38
+
39
+ /**
40
+ * Cancels all text currently being spoken and any that has been queued.
41
+ */
42
+ //% shim=tts::_cancel
43
+ //% blockId=tts_cancel
44
+ //% block="cancel speech"
45
+ //% weight=70
46
+ function cancel(): void;
47
+ }
@@ -0,0 +1,72 @@
1
+ namespace pxsim.tts {
2
+ export function _getLanguageCode() {
3
+ return window.navigator.language;
4
+ }
5
+
6
+ export function _speakAsync(text: string, pitch?: number, rate?: number, volume?: number, language?: string, onStart?: RefAction, onBoundary?: RefAction): Promise<void> {
7
+ return new Promise<void>((resolve, reject) => {
8
+ const utterance = new SpeechSynthesisUtterance(text);
9
+ utterance.voice = getVoiceForLanguage(language || _getLanguageCode());
10
+
11
+ if (pitch != undefined) utterance.pitch = pitch;
12
+ if (rate != undefined) utterance.rate = rate;
13
+ if (volume != undefined) utterance.volume = volume;
14
+
15
+ utterance.onend = () => resolve();
16
+ utterance.onerror = reject;
17
+
18
+ if (onStart) {
19
+ utterance.onstart = () => runtime.runFiberAsync(onStart);
20
+ }
21
+
22
+ if (onBoundary) {
23
+ utterance.onboundary = event => {
24
+ const offset = event.charIndex;
25
+ const nextWord = text.substring(offset).split(/\s/).shift();
26
+
27
+ runtime.runFiberAsync(onBoundary, offset, nextWord, text);
28
+ }
29
+ }
30
+
31
+ speechSynthesis.speak(utterance);
32
+ });
33
+ }
34
+
35
+ export function _pause() {
36
+ speechSynthesis.pause();
37
+ }
38
+
39
+ export function _isPaused(): boolean {
40
+ return speechSynthesis.paused;
41
+ }
42
+
43
+ export function _resume() {
44
+ speechSynthesis.resume();
45
+ }
46
+
47
+ export function _cancel() {
48
+ speechSynthesis.cancel();
49
+ }
50
+
51
+ function getVoiceForLanguage(language: string): SpeechSynthesisVoice {
52
+ language = language.toLowerCase();
53
+ const generalCode = language.substring(0, 2);
54
+
55
+ let bestMatch: SpeechSynthesisVoice;
56
+ let bestNonlocalMatch: SpeechSynthesisVoice;
57
+
58
+ for (const voice of speechSynthesis.getVoices()) {
59
+ const current = voice.lang.toLowerCase();
60
+ if (current === language) {
61
+ if (voice.localService) return voice;
62
+ else bestNonlocalMatch = voice;
63
+ }
64
+ else if (current.substring(0, 2) === generalCode) {
65
+ if (!bestMatch && voice.localService) bestMatch = voice;
66
+ if (!bestNonlocalMatch && !voice.localService) bestNonlocalMatch = voice
67
+ }
68
+ }
69
+
70
+ return bestMatch || bestNonlocalMatch || (language !== "en-us" ? getVoiceForLanguage("en-US") : undefined);
71
+ }
72
+ }
@@ -0,0 +1,70 @@
1
+ namespace tts {
2
+ class TextToSpeechState {
3
+ boundaryListeners: ((offset: number, nextWord: string, fullText: string) => void)[];
4
+
5
+ constructor() {
6
+ this.boundaryListeners = [];
7
+ }
8
+ }
9
+
10
+ let state: TextToSpeechState;
11
+
12
+ /**
13
+ * Runs code each time a word or sentence boundary is reached in text being spoken
14
+ */
15
+ //% blockId=tts_onWordSpoken
16
+ //% block="on word spoken from $fullText at $offset with $nextWord"
17
+ //% draggableParameters="reporter"
18
+ //% weight=10
19
+ export function onWordSpoken(handler: (offset: number, nextWord: string, fullText: string) => void) {
20
+ getState().boundaryListeners.push(handler);
21
+ }
22
+
23
+ /**
24
+ * Speak some text using the computer's text to speech voice and pause until the speaking has finished.
25
+ * If some text is already being spoken, this text will be queued until the other text finishes.
26
+ *
27
+ * @param text The text to speak
28
+ * @param volume The volume to speak at
29
+ * @param pitch A pitch modifier for moving the pitch of text up or down
30
+ * @param rate The rate at which the text will be spoken; higher is faster
31
+ * @param language The ISO language code for the text to be spoken; defaults to the system language
32
+ */
33
+ //% blockId=tts_speakText
34
+ //% block="speak $text||with volume $volume pitch $pitch rate $rate language $language"
35
+ //% inlineInputMode=inline
36
+ //% volume.min=0
37
+ //% volume.max=255
38
+ //% volume.defl=128
39
+ //% pitch.min=0
40
+ //% pitch.max=255
41
+ //% pitch.defl=128
42
+ //% rate.min=0
43
+ //% rate.max=255
44
+ //% rate.defl=25
45
+ //% weight=100
46
+ export function speakText(text: string, volume = 128, pitch = 128, rate = 25, language?: string) {
47
+ // Ranges from 0 to 1
48
+ volume = Math.map(Math.clamp(0, 255, volume), 0, 255, 0, 1);
49
+ // Ranges from 0 to 2
50
+ pitch = Math.map(Math.clamp(0, 255, pitch), 0, 255, 0, 2);;
51
+ // Ranges from 0.1 to 10
52
+ rate = Math.map(Math.clamp(0, 255, rate), 0, 255, 0.1, 10);
53
+
54
+ tts.speak(text, pitch, rate, volume, language, undefined, onBoundary);
55
+ }
56
+
57
+ function onBoundary(offset: number, nextWord: string, fullText: string) {
58
+ for (const handler of getState().boundaryListeners) {
59
+ control.runInParallel(() => handler(offset, nextWord, fullText))
60
+ }
61
+ }
62
+
63
+ function getState() {
64
+ if (!state) {
65
+ state = new TextToSpeechState();
66
+ }
67
+
68
+ return state;
69
+ }
70
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pxt-common-packages",
3
- "version": "9.4.1",
3
+ "version": "9.4.5",
4
4
  "description": "Microsoft MakeCode (PXT) common packages",
5
5
  "keywords": [
6
6
  "MakeCode",