MCPcopy Create free account
hub / github.com/codecombat/codecombat / preload

Function preload

app/core/store/modules/voiceOver.js:11–55  ·  view source on GitHub ↗
({ dispatch }, { dialogNode, speakerThangType })

Source from the content-addressed store, hash-verified

9 // Asynchronously preloads a voice over track
10 // returning a promise including a soundId or undefined
11 preload ({ dispatch }, { dialogNode, speakerThangType }) {
12 let heroGender = 'male'
13 const userThangType = (me.get('ozariaUserOptions') || {}).cinematicThangTypeOriginal || ozariaCinematicHeroes['hero-b']
14 if ([ozariaCinematicHeroes['hero-b'], ozariaCinematicHeroes['hero-c'], ozariaCinematicHeroes['hero-e']].indexOf(userThangType) !== -1) {
15 heroGender = 'female'
16 }
17
18 let voiceOver = dialogNode.voiceOver
19 if (voiceOver?.male || voiceOver?.female) {
20 voiceOver = voiceOver[heroGender]
21 }
22
23 if (!voiceOver?.mp3 && !voiceOver?.ogg) {
24 // Determine whether to request TTS
25 const originalText = dialogNode.originalMessage || dialogNode.text
26 const text = i18n(dialogNode, 'text')
27 const textIsLocalized = text !== originalText
28 if (text) {
29 let plainText = markdownToPlainText(text)
30
31 // Transform common mispronounced words to make them more phonetic for the TTS engine
32 plainText = plainText.replace(/Acodus/g, 'akodus') // This gets this emphasis properly onto the second syllable
33
34 // Remove template interpolation, like "I hate to do this, {%=o.name%}, but the carnival is about to pack up and head east."
35 plainText = plainText.replace(/ ?\{%=.+?\} ?/g, '')
36
37 if (speakerThangType === 'hero') {
38 speakerThangType = heroGender === 'male' ? 'hero-a' : 'hero-b'
39 }
40
41 const lang = me.get('preferredLanguage', true)
42 const textLanguage = (textIsLocalized || lang === 'en-GB') ? lang : 'en-US'
43 const ttsPath = `text-to-speech/${textLanguage}/${speakerThangType}/${encodeURIComponent(plainText)}`
44 voiceOver = { mp3: ttsPath + '.mp3', ogg: ttsPath + '.ogg' }
45 } else {
46 return Promise.resolve(undefined)
47 }
48 }
49
50 return dispatch('audio/playSound', {
51 track: 'voiceOver',
52 autoplay: false,
53 src: Object.values(voiceOver).map(f => `/file/${f}`)
54 }, { root: true })
55 },
56
57 /**
58 * Plays Voice Over, fading out other voices if they are speaking.

Callers

nothing calls this directly

Calls 4

i18nFunction · 0.90
markdownToPlainTextFunction · 0.90
dispatchFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected