@@ -9,12 +9,15 @@ https://github.com/curiousdannii/asyncglk
9
9
10
10
*/
11
11
12
- import { fetch_resource } from '../../common/file/browser.js'
12
+ import { fetch_resource , parse_base64 } from '../../common/file/browser.js'
13
13
import * as protocol from '../../common/protocol.js'
14
14
import WebGlkOte from './web.js'
15
15
16
16
import GlkAudio_init , { decode as GlkAudio_decode , wasm as GlkAudio_is_ready } from 'glkaudio'
17
17
18
+ // From https://github.com/compulim/web-speech-cognitive-services/issues/34
19
+ const priming_mp3 = 'SUQzBAAAAAAAI1RTU0UAAAAPAAADTGF2ZjU3LjU2LjEwMQAAAAAAAAAAAAAA//tAwAAAAAAAAAAAAAAAAAAAAAAASW5mbwAAAA8AAAACAAABhgC7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7//////////////////////////////////////////////////////////////////8AAAAATGF2YzU3LjY0AAAAAAAAAAAAAAAAJAUHAAAAAAAAAYYoRBqpAAAAAAD/+xDEAAPAAAGkAAAAIAAANIAAAARMQU1FMy45OS41VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVf/7EMQpg8AAAaQAAAAgAAA0gAAABFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV'
20
+
18
21
export class SoundChannelManager extends Map < number , SoundChannel > {
19
22
private context : AudioContext
20
23
private glkote : WebGlkOte
@@ -23,6 +26,9 @@ export class SoundChannelManager extends Map<number, SoundChannel> {
23
26
super ( )
24
27
this . glkote = glkote
25
28
this . context = new AudioContext ( )
29
+
30
+ // Try to prime the audio system so that sounds starting after a timer will work
31
+ this . prime ( )
26
32
}
27
33
28
34
async update ( schannels : protocol . SoundChannelUpdate [ ] ) {
@@ -50,6 +56,21 @@ export class SoundChannelManager extends Map<number, SoundChannel> {
50
56
}
51
57
}
52
58
}
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
+ }
53
74
}
54
75
55
76
export class SoundChannel {
0 commit comments