Closed Hanhan139 closed 1 year ago
This. This works :D Thx to Jonas for helping me!
//Math and randomizers
export function func_RandomNumberTen(): number {
return func_RandomNumberRange(0, 10);
}
//Voice output with sound
export async function func_randomSoundHERvoice(){
let randomNumber = func_RandomNumberTen();
switch (randomNumber) {
case 0:
return sound.voices.default[0];
case 1:
return sound.voices.default[1];
case 2:
return sound.voices.default[2];
case 3:
return sound.voices.default[3];
case 4:
return sound.voices.default[4];
case 5:
return sound.voices.default[5];
case 6:
return sound.voices.default[6];
case 7:
return sound.voices.default[7];
case 8:
return sound.voices.default[8];
case 9:
return sound.voices.default[9];
case 10:
return sound.voices.default[10];
default:
return sound.voices.default[0];
};
}
export async function func_speechWithAudio(
_sentenceNarrator:string = "", _sentenceContent:string = "", _sentenceSound:string = "", _sentenceDelay:number = 30,
_waitForNext:boolean = true, _skippableDialogue:boolean = true,
) {
let delayTime = new ƒ.Time();
let voiceChange = await func_randomSoundHERvoice();
let sentenceLength = _sentenceContent.length;
// let forwardTickerSaver = ƒS.Speech.signalForwardTicker;
ƒS.Speech.setTickerDelays(_sentenceDelay);
// forwardTickerSaver = ƒS.Speech.signalForwardTicker;
if (!_skippableDialogue){
ƒS.Speech.signalForwardTicker = ƒS.Progress.defineSignal([() => delayTime.delay(_sentenceDelay*sentenceLength)]);
} else {
ƒS.Speech.signalForwardTicker = ƒS.Progress.defineSignal([() => ƒS.getKeypress(ƒ.KEYBOARD_CODE.SPACE), ƒS.EVENT.POINTERDOWN]);
// ƒS.Speech.signalForwardTicker = ƒS.Progress.defineSignal([() => true]);
}
ƒS.Speech.tell(_sentenceNarrator, _sentenceContent);
let promises: Promise<void>[] = [];
let prmTick: Promise<void> = new Promise(async (_resolve) => {
//Sound ausgabe nach länge des Texts
for (let x: number = 0; x < sentenceLength; x++){
if (_sentenceSound != ""){
if (_sentenceSound == "HER"){
ƒS.Sound.play(voiceChange, 1, false); //Uses one of multiple randomly chosen sounds to generate voice changes with every line
}else if (_sentenceSound == "CHAOS"){
ƒS.Sound.play(await func_randomSoundHERvoice(), 1, false); //Plays a random assortment of sounds
}else {
ƒS.Sound.play(_sentenceSound, 1, false); //Plays the assigned sound
};
};
await delayTime.delay(_sentenceDelay);
};
console.log("Before Resolve, Finished");
_resolve(null);
});
promises.push(prmTick);
if (_skippableDialogue){
let prmInput: Promise<void> = new Promise(async (_resolve) => {
console.log("PRMinput START");
await Promise.any([ƒS.getKeypress(ƒ.KEYBOARD_CODE.SPACE), ƒS.getInput([ƒS.EVENT.POINTERDOWN])]);
delayTime.clearAllTimers();
console.log("PRMinput FIN");
_resolve(null);
console.log("PRMinput PASTRESOLVE");
});
promises.push(prmInput);
};
await Promise.race(promises);
if (!_skippableDialogue){
await delayTime.delay(1000);
};
if (_waitForNext){
await Promise.any([ƒS.getKeypress(ƒ.KEYBOARD_CODE.SPACE), ƒS.getInput([ƒS.EVENT.POINTERDOWN])]);
};
ƒS.Speech.signalForwardTicker = ƒS.Progress.defineSignal([() => ƒS.getKeypress(ƒ.KEYBOARD_CODE.SPACE), ƒS.EVENT.POINTERDOWN]);
};
As mentioned in the discord, I made speech with sound output per letter called: func_speechWithAudio();
-- What's wrong? -- a) Doesn't await. The text simply speeds on to the next, not waiting for the mouseclick b) IF I click, the text nicely displays as whole, but it still plays all the sounds, AND only continues AFTER all sounds for all letters have been played c) The sounds aren't being fully played, but chopped off due to delay time. I'd like them to finish playing without obstructing the next sound from starting to play if possible
-- Extra detailing -- The function counts the length of the sentence, and plays a sound for every letter that isn't an empty space. Just like speech it takes the name of the speaker and the delaytime.
I checked the sourcecode of Fudge and I found there is a boolean called waitForNext. I tried to implement one just like that in my speech output function, but since I'm not a programmer have no idea how to/failed to tackle the issue of interrupting a process. There is a boolean _waitForNext = true in my input variables; It doesn't actually do anything at the moment.
-- File/s: -- scn_Intro.ts, def_functions.ts Audio files: VN_Seeyoutomorrow_FudgeStory\Assets\SFX\Voice Iterating from 0 to 10 -- Git: -- https://github.com/Hanhan139/HFU_VisualNovel -- Code: ---
`export async function func_speechWithAudio( _sentenceNarrator:string = "", _sentenceContent:string = "", _sentenceSound:string = "", _sentenceDelay:number = 30, _waitForNext = true, ) {
let delayTime = new ƒ.Time(); let voiceChange = await func_randomSoundHERvoice(); let sentenceLength = _sentenceContent.length;
How to call it: