markdown-up 5.3.0 → 5.3.1
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/lib/voice.js +14 -2
- package/package.json +1 -1
package/lib/voice.js
CHANGED
|
@@ -277,6 +277,18 @@ function skipStarts(sentences) {
|
|
|
277
277
|
}
|
|
278
278
|
|
|
279
279
|
|
|
280
|
+
// Create a voice audio context. Where the browser has audio sessions (Safari), the page's audio is first declared
|
|
281
|
+
// playback audio (like a podcast's) - Web Audio is otherwise ambient audio, which an iPhone in silent mode mutes on its
|
|
282
|
+
// speaker.
|
|
283
|
+
function createAudioContext(window) {
|
|
284
|
+
const audioSession = (window.navigator ?? {}).audioSession ?? null;
|
|
285
|
+
if (audioSession !== null) {
|
|
286
|
+
audioSession.type = 'playback';
|
|
287
|
+
}
|
|
288
|
+
return new window.AudioContext({'sampleRate': voiceSampleRate});
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
|
|
280
292
|
// The next task - a promise resolved by a message to the page itself (a timer would be throttled in background tabs)
|
|
281
293
|
function nextTask() {
|
|
282
294
|
return new Promise((resolve) => {
|
|
@@ -412,7 +424,7 @@ export class MarkdownUpVoice {
|
|
|
412
424
|
speak(paragraphs, final, key) {
|
|
413
425
|
this.runStop();
|
|
414
426
|
if (this.audioContext === null) {
|
|
415
|
-
this.audioContext =
|
|
427
|
+
this.audioContext = createAudioContext(this.window);
|
|
416
428
|
}
|
|
417
429
|
this.audioContext.resume();
|
|
418
430
|
this.playback = {key, final, 'sentences': playbackSentences(paragraphs, final), 'position': 0, 'playing': true, 'run': null};
|
|
@@ -567,7 +579,7 @@ export class MarkdownUpVoice {
|
|
|
567
579
|
// until the user interacts with the page, so the context is resumed when they do.
|
|
568
580
|
lineContext() {
|
|
569
581
|
if (this.lineAudioContext === null) {
|
|
570
|
-
const audioContext =
|
|
582
|
+
const audioContext = createAudioContext(this.window);
|
|
571
583
|
this.lineAudioContext = audioContext;
|
|
572
584
|
const resume = () => {
|
|
573
585
|
if (audioContext.state !== 'running') {
|