-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
svub
committed
Sep 29, 2023
1 parent
8d283f3
commit f0444ca
Showing
11 changed files
with
30,421 additions
and
82 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,18 @@ | ||
<template> | ||
<div id="app"> | ||
<div id="nav"> | ||
<router-link to="/">Home</router-link> | | ||
<router-link to="/sources">Sources</router-link> | ||
</div> | ||
<router-view/> | ||
</div> | ||
<template lang="pug"> | ||
#app | ||
h1 Text adventure book creator! | ||
//- #nav | ||
//- router-link(to="/") Home | ||
//- router-link(to="/sources") Sources | ||
router-view | ||
</template> | ||
|
||
<style lang="stylus"> | ||
#app | ||
font-family Avenir, Helvetica, Arial, sans-serif | ||
-webkit-font-smoothing antialiased | ||
-moz-osx-font-smoothing grayscale | ||
text-align center | ||
text-align left | ||
color #2c3e50 | ||
margin-top 60px | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,73 @@ | ||
import Vue from 'vue' | ||
import Vuex from 'vuex' | ||
import { Book, Config } from '../shared/entities'; | ||
import VuexPersistence from 'vuex-persist'; | ||
import { getField, updateField } from 'vuex-map-fields'; | ||
|
||
Vue.use(Vuex) | ||
|
||
interface AppState { | ||
book: Book | null; | ||
config: Config | null; | ||
sources: string; | ||
azureKey: string | null; | ||
azureRegion: string | null; | ||
azureVoice: string | null; | ||
decisionIntroSingle: string; | ||
decisionIntro: string; | ||
decisionConjunction: string; | ||
maxMBytesPerZip: number; | ||
replacements: string; | ||
synthesisProgress: number; | ||
synthesisLimit: number; | ||
} | ||
|
||
const state: AppState = { | ||
book: null, | ||
config: null, | ||
sources: "", | ||
azureKey: null, | ||
azureRegion: null, | ||
azureVoice: "de-DE-KillianNeural", | ||
decisionIntroSingle: "", | ||
decisionIntro: "", | ||
decisionConjunction: "", | ||
maxMBytesPerZip: 100, | ||
replacements: "", | ||
synthesisProgress: 0, | ||
synthesisLimit: 0, | ||
} | ||
|
||
export default new Vuex.Store({ | ||
const vuexLocal = new VuexPersistence<AppState>({ | ||
storage: window.localStorage | ||
}) | ||
|
||
export default new Vuex.Store<AppState>({ | ||
state, | ||
getters: { | ||
getField, | ||
}, | ||
mutations: { | ||
setBook(state, { book }: { book: Book }) { | ||
state.book = book; | ||
}, | ||
setConfig(state, { config }: { config: Config }) { | ||
state.config = config; | ||
}, | ||
// setAzureKey(state, azureKey: string) { | ||
// state.azureKey = azureKey; | ||
// }, | ||
// setAzureRegion(state, azureRegion: string) { | ||
// state.azureRegion = azureRegion; | ||
// }, | ||
// setAzureVoice(state, azureVoice: string) { | ||
// state.azureVoice = azureVoice; | ||
// }, | ||
updateField, | ||
}, | ||
actions: { | ||
}, | ||
modules: { | ||
} | ||
}, | ||
plugins: [vuexLocal.plugin], | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { ResultReason, SpeechConfig, SpeechSynthesisOutputFormat, SpeechSynthesizer } | ||
from "microsoft-cognitiveservices-speech-sdk"; | ||
|
||
export type TextAndFilename = { | ||
text: string; | ||
filename: string; | ||
} | ||
|
||
export function createSynthesizer(key, region, voice) { | ||
const speechConfig = SpeechConfig.fromSubscription(key, region); | ||
speechConfig.speechSynthesisOutputFormat = SpeechSynthesisOutputFormat.Audio48Khz96KBitRateMonoMp3; | ||
speechConfig.speechSynthesisVoiceName = voice; | ||
return new SpeechSynthesizer(speechConfig); | ||
} | ||
|
||
export async function synthesizeAudio(text: string, synthesizer: SpeechSynthesizer) { | ||
const result = new Promise<{ data: ArrayBuffer; message: string }>((resolve, reject) => { | ||
synthesizer.speakTextAsync(text, | ||
result => { | ||
if (result.reason === ResultReason.SynthesizingAudioCompleted) { | ||
resolve({ | ||
data: result.audioData, | ||
message: `Synthesis successful. Audio data: ${result.audioData.byteLength} bytes.` | ||
}); | ||
} else if (result.reason === ResultReason.Canceled) { | ||
reject("Synthesis failed. Error detail: " + result.errorDetails); | ||
} | ||
reject("Unknown error " + result); | ||
}, | ||
err => reject("Error: " + err)); | ||
}); | ||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Book, ElementType, HasElements, Reference, hasElements, Element } from "@/shared/entities"; | ||
|
||
export function downloadFile(data: Blob, fileName: string) { | ||
const url = window.URL.createObjectURL(data); | ||
const link = document.createElement('a'); | ||
link.href = url; | ||
link.download = fileName; | ||
document.body.appendChild(link); | ||
link.click(); | ||
window.URL.revokeObjectURL(url); | ||
link.remove(); | ||
} | ||
|
||
export type ElementReference<Type extends Element> = Reference & { | ||
element: Type; | ||
} | ||
|
||
export function getAllElements<Type extends Element>(book: Book, filterType?: ElementType): ElementReference<Type>[] { | ||
function findElements(chapterId: string, sectionId: string, has: HasElements) { | ||
const results: ElementReference<Type>[] = []; | ||
has.elements.forEach((element) => { | ||
if (hasElements(element)) { | ||
results.push(...findElements(chapterId, sectionId, element as HasElements)); | ||
} | ||
if (filterType && element.type != filterType) return; | ||
results.push({ | ||
chapterId, | ||
sectionId, | ||
element: element as Type, | ||
}); | ||
}); | ||
return results; | ||
} | ||
|
||
const elements: ElementReference<Type>[] = []; | ||
book.chapters.forEach((chapter) => { | ||
chapter.sections.forEach((section) => { | ||
elements.push(...findElements(chapter.id, section.id, section)); | ||
}); | ||
}); | ||
return elements; | ||
} |
Oops, something went wrong.