@@ -9,12 +9,15 @@ https://github.com/curiousdannii/asyncglk
99
1010*/
1111
12- import { fetch_resource } from '../../common/file/browser.js'
12+ import { fetch_resource , parse_base64 } from '../../common/file/browser.js'
1313import * as protocol from '../../common/protocol.js'
1414import WebGlkOte from './web.js'
1515
1616import GlkAudio_init , { decode as GlkAudio_decode , wasm as GlkAudio_is_ready } from 'glkaudio'
1717
18+ // From https://github.com/compulim/web-speech-cognitive-services/issues/34
19+ const priming_mp3 = 'SUQzBAAAAAAAI1RTU0UAAAAPAAADTGF2ZjU3LjU2LjEwMQAAAAAAAAAAAAAA//tAwAAAAAAAAAAAAAAAAAAAAAAASW5mbwAAAA8AAAACAAABhgC7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7//////////////////////////////////////////////////////////////////8AAAAATGF2YzU3LjY0AAAAAAAAAAAAAAAAJAUHAAAAAAAAAYYoRBqpAAAAAAD/+xDEAAPAAAGkAAAAIAAANIAAAARMQU1FMy45OS41VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVf/7EMQpg8AAAaQAAAAgAAA0gAAABFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV'
20+
1821export class SoundChannelManager extends Map < number , SoundChannel > {
1922 private context : AudioContext
2023 private glkote : WebGlkOte
@@ -23,6 +26,9 @@ export class SoundChannelManager extends Map<number, SoundChannel> {
2326 super ( )
2427 this . glkote = glkote
2528 this . context = new AudioContext ( )
29+
30+ // Try to prime the audio system so that sounds starting after a timer will work
31+ this . prime ( )
2632 }
2733
2834 async update ( schannels : protocol . SoundChannelUpdate [ ] ) {
@@ -50,6 +56,21 @@ export class SoundChannelManager extends Map<number, SoundChannel> {
5056 }
5157 }
5258 }
59+
60+ private async prime ( ) {
61+ const context = this . context
62+
63+ const source = this . context . createBufferSource ( )
64+ const data = await parse_base64 ( priming_mp3 )
65+ source . buffer = await context . decodeAudioData ( data . buffer )
66+
67+ source . connect ( context . destination )
68+ source . start ( )
69+ setTimeout ( ( ) => {
70+ source . disconnect ( )
71+ source . stop ( )
72+ } , 10 )
73+ }
5374}
5475
5576export class SoundChannel {
0 commit comments