markdown-up 5.2.1 → 5.3.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 +36 -1
- package/lib/app.js +457 -178
- package/lib/appImports.js +4 -0
- package/lib/scriptLibrary.js +151 -0
- package/lib/voice.js +813 -0
- package/package.json +6 -5
package/lib/appImports.js
CHANGED
|
@@ -16,7 +16,11 @@ import 'bare-script/lib/value.js';
|
|
|
16
16
|
// element-model
|
|
17
17
|
import 'element-model/lib/elementModel.js';
|
|
18
18
|
|
|
19
|
+
// picovox (its synthesis modules and models are loaded when voice playback is first used)
|
|
20
|
+
import 'picovox/lib/sentences.js';
|
|
21
|
+
|
|
19
22
|
// markdown-up
|
|
20
23
|
export {MarkdownUp} from './app.js';
|
|
21
24
|
import './script.js';
|
|
22
25
|
import './scriptLibrary.js';
|
|
26
|
+
import './voice.js';
|
package/lib/scriptLibrary.js
CHANGED
|
@@ -386,6 +386,150 @@ const sessionStorageSetArgs = valueArgsModel([
|
|
|
386
386
|
]);
|
|
387
387
|
|
|
388
388
|
|
|
389
|
+
//
|
|
390
|
+
// Voice functions
|
|
391
|
+
//
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
// $function: voiceClose
|
|
395
|
+
// $group: voice
|
|
396
|
+
// $doc: Close the voice playback started by `voiceSpeak`, if any, and stop the voice lines started by `voiceSay`
|
|
397
|
+
function voiceClose(unusedArgs, options) {
|
|
398
|
+
options.voice.close();
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
|
|
402
|
+
// $function: voiceLoad
|
|
403
|
+
// $group: voice
|
|
404
|
+
// $doc: Load the speech synthesizer, so that the first `voiceSay` voice line (or `voiceSpeak` voice playback) starts
|
|
405
|
+
// $doc: without delay - otherwise, it's loaded when it's first used. Call it when the page is rendered.
|
|
406
|
+
function voiceLoad(unusedArgs, options) {
|
|
407
|
+
options.voice.load();
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
// $function: voiceReady
|
|
412
|
+
// $group: voice
|
|
413
|
+
// $doc: Test whether voice lines can be heard. A browser may not let audio start until the user interacts with the
|
|
414
|
+
// $doc: page (a click or a key press), and `voiceSay` drops a line that can't be heard - so an application that says
|
|
415
|
+
// $doc: lines on its own (e.g., a film that plays when the page loads) can wait to start until this is true.
|
|
416
|
+
// $return: true if the browser has let the voice lines' audio start, false otherwise
|
|
417
|
+
function voiceReady(unusedArgs, options) {
|
|
418
|
+
return options.voice.ready();
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
// $function: voiceSay
|
|
423
|
+
// $group: voice
|
|
424
|
+
// $doc: Say a line of text aloud in a voice and a speaking style - a performance cue, like a film's line of dialogue.
|
|
425
|
+
// $doc: Unlike `voiceSpeak`, the text is plain text, there is no voice playback bar, and a line plays over any other
|
|
426
|
+
// $doc: lines (and over the voice playback). The lines stop when `voiceClose` is called and when the page is
|
|
427
|
+
// $doc: rendered anew. A line that can't be heard (a browser may not let audio start until the user interacts with
|
|
428
|
+
// $doc: the page - see `voiceReady`) is dropped. For example:
|
|
429
|
+
// $doc:
|
|
430
|
+
// $doc: ```barescript
|
|
431
|
+
// $doc: function myAppOnClick():
|
|
432
|
+
// $doc: voiceSay('Go for ignition.', 'james')
|
|
433
|
+
// $doc: voiceSay('Ignition!', 'sarah', 'shouting')
|
|
434
|
+
// $doc: endfunction
|
|
435
|
+
// $doc: ```
|
|
436
|
+
// $doc:
|
|
437
|
+
// $doc: The voices are "michael" (the default), "sarah", "male", "female", "james", "helen", "robert", "amy",
|
|
438
|
+
// $doc: "david", "kate", "thomas", and "grace".
|
|
439
|
+
// $doc:
|
|
440
|
+
// $doc: The speaking styles are "neutral" (the default), the emotions "angry", "happy", "sad", "fearful", and
|
|
441
|
+
// $doc: "disgusted", and the modes "whisper", "soft", "shouting", "dialogue", and "exclaim".
|
|
442
|
+
// $arg text: The text to say
|
|
443
|
+
// $arg voice: Optional (default is null). The voice. An unknown voice is the default voice.
|
|
444
|
+
// $arg style: Optional (default is "neutral"). The speaking style. An unknown style is the default style.
|
|
445
|
+
// $arg rate: Optional (default is 1). The speaking rate, from 0.5 to 2.
|
|
446
|
+
function voiceSay(args, options) {
|
|
447
|
+
const [text, voice, style, rate] = valueArgsValidate(voiceSayArgs, args);
|
|
448
|
+
options.voice.say(text, voice, style, rate);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
const voiceSayArgs = valueArgsModel([
|
|
452
|
+
{'name': 'text', 'type': 'string'},
|
|
453
|
+
{'name': 'voice', 'type': 'string', 'nullable': true},
|
|
454
|
+
{'name': 'style', 'type': 'string', 'default': 'neutral'},
|
|
455
|
+
{'name': 'rate', 'type': 'number', 'default': 1, 'gte': 0.5, 'lte': 2}
|
|
456
|
+
]);
|
|
457
|
+
|
|
458
|
+
|
|
459
|
+
// $function: voiceSetText
|
|
460
|
+
// $group: voice
|
|
461
|
+
// $doc: Set the text of the voice playback started by `voiceSpeak`, if any. A playback's text may grow as it plays
|
|
462
|
+
// $doc: (e.g., a response that's still being generated) - if the words that have already played change, the playback
|
|
463
|
+
// $doc: starts again at the beginning.
|
|
464
|
+
// $arg text: The Markdown text to read aloud
|
|
465
|
+
// $arg final: Optional (default is true). If false, more text is coming - the text's last sentence is held back, and
|
|
466
|
+
// $arg final: playback pauses at the end of the text.
|
|
467
|
+
function voiceSetText(args, options) {
|
|
468
|
+
const [text, final] = valueArgsValidate(voiceSetTextArgs, args);
|
|
469
|
+
options.voice.setText(text, final);
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
const voiceSetTextArgs = valueArgsModel([
|
|
473
|
+
{'name': 'text', 'type': 'string'},
|
|
474
|
+
{'name': 'final', 'type': 'boolean', 'default': true}
|
|
475
|
+
]);
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
// $function: voiceSpeak
|
|
479
|
+
// $group: voice
|
|
480
|
+
// $doc: Start reading Markdown text aloud, closing any voice playback. Call it in an event handler (e.g., a click),
|
|
481
|
+
// $doc: so the browser lets the audio start. MarkdownUp shows its voice playback bar (play and pause, rewind, skip
|
|
482
|
+
// $doc: back and forward by section, voice, and speaking rate) at the bottom of the window - or, if the page has an
|
|
483
|
+
// $doc: element with the ID "markdownUpVoice", in that element. Code blocks and images aren't read. For example:
|
|
484
|
+
// $doc:
|
|
485
|
+
// $doc: ```barescript
|
|
486
|
+
// $doc: function myAppMain():
|
|
487
|
+
// $doc: lines = ['# Hello', '', 'This text is read aloud.']
|
|
488
|
+
// $doc: markdownPrint(lines)
|
|
489
|
+
// $doc: elementModelRender({ \
|
|
490
|
+
// $doc: 'html': 'p', \
|
|
491
|
+
// $doc: 'elem': { \
|
|
492
|
+
// $doc: 'html': 'a', \
|
|
493
|
+
// $doc: 'attr': {'style': 'cursor: pointer;'}, \
|
|
494
|
+
// $doc: 'elem': {'text': 'Read Aloud'}, \
|
|
495
|
+
// $doc: 'callback': {'click': systemPartial(myAppOnReadAloud, arrayJoin(lines, '\n'))} \
|
|
496
|
+
// $doc: } \
|
|
497
|
+
// $doc: })
|
|
498
|
+
// $doc: endfunction
|
|
499
|
+
// $doc:
|
|
500
|
+
// $doc: function myAppOnReadAloud(text):
|
|
501
|
+
// $doc: voiceSpeak(text)
|
|
502
|
+
// $doc: endfunction
|
|
503
|
+
// $doc:
|
|
504
|
+
// $doc: myAppMain()
|
|
505
|
+
// $doc: ```
|
|
506
|
+
// $arg text: The Markdown text to read aloud
|
|
507
|
+
// $arg final: Optional (default is true). If false, more text is coming (see `voiceSetText`).
|
|
508
|
+
// $arg key: Optional (default is null). The playback's key value, returned by `voiceState`.
|
|
509
|
+
function voiceSpeak(args, options) {
|
|
510
|
+
const [text, final, key] = valueArgsValidate(voiceSpeakArgs, args);
|
|
511
|
+
options.voice.speak(text, final, key);
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
const voiceSpeakArgs = valueArgsModel([
|
|
515
|
+
{'name': 'text', 'type': 'string'},
|
|
516
|
+
{'name': 'final', 'type': 'boolean', 'default': true},
|
|
517
|
+
{'name': 'key'}
|
|
518
|
+
]);
|
|
519
|
+
|
|
520
|
+
|
|
521
|
+
// $function: voiceState
|
|
522
|
+
// $group: voice
|
|
523
|
+
// $doc: Get the state of the voice playback started by `voiceSpeak`
|
|
524
|
+
// $return: The voice playback state object, or null if there is no voice playback. The state object has the
|
|
525
|
+
// $return: following members:
|
|
526
|
+
// $return: - `key` - The playback's key value
|
|
527
|
+
// $return: - `playing` - If true, the playback is playing (not paused)
|
|
528
|
+
function voiceState(unusedArgs, options) {
|
|
529
|
+
return options.voice.state();
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
|
|
389
533
|
//
|
|
390
534
|
// Window functions
|
|
391
535
|
//
|
|
@@ -822,6 +966,13 @@ export const markdownScriptFunctions = {
|
|
|
822
966
|
sessionStorageGet,
|
|
823
967
|
sessionStorageRemove,
|
|
824
968
|
sessionStorageSet,
|
|
969
|
+
voiceClose,
|
|
970
|
+
voiceLoad,
|
|
971
|
+
voiceReady,
|
|
972
|
+
voiceSay,
|
|
973
|
+
voiceSetText,
|
|
974
|
+
voiceSpeak,
|
|
975
|
+
voiceState,
|
|
825
976
|
windowClipboardRead,
|
|
826
977
|
windowClipboardWrite,
|
|
827
978
|
windowHeight,
|