feat: add dynamic voice setting

This commit is contained in:
Youwen Wu 2024-02-27 00:00:08 -08:00
parent 21eb0411d1
commit 0d77ea7f84
Signed by: youwen5
GPG key ID: 865658ED1FE61EC3
4 changed files with 187 additions and 173 deletions

View file

@ -1,8 +1,7 @@
import type CameraControls from 'camera-controls' import type CameraControls from "camera-controls";
import { writable } from 'svelte/store' import { writable } from "svelte/store";
import Hornet from '../../models/Hornet.svelte' import type { Mesh, Object3DEventMap } from "three";
import type { Mesh, Object3DEventMap } from 'three' import type { Group } from "three/examples/jsm/libs/tween.module.js";
import type { Group } from 'three/examples/jsm/libs/tween.module.js'
export const cameraControls = writable<CameraControls>() export const cameraControls = writable<CameraControls>();
export const mesh = writable<Mesh>() export const mesh = writable<Mesh>();

View file

@ -14,47 +14,44 @@ Sequences should be either event-driven or periodic. In the case of periodic
sequences, invoke them in the periodicSequence function sequences, invoke them in the periodicSequence function
*/ */
import { Notifications } from '../Notifications/notifications' import { Notifications } from "../Notifications/notifications";
import { sequenceStore } from '../stores/sequenceStore' import { sequenceStore } from "../stores/sequenceStore";
import { settingsStore } from '../stores/settingsStore' import { settingsStore } from "../stores/settingsStore";
import { get } from 'svelte/store' import { get } from "svelte/store";
import getVoicePath from '../utils/getVoicePath' import getVoicePath from "../utils/getVoicePath";
import { tick } from 'svelte' import { tick } from "svelte";
// await a "tick" (a svelte update frame) at the start of every sequence so that // await a "tick" (a svelte update frame) at the start of every sequence so that
// state is synced and no weird side effects occur // state is synced and no weird side effects occur
export const initializationSequence = async () => { export const initializationSequence = async () => {
await tick() await tick();
Notifications.info('Jankboard initialized!', { Notifications.info("Jankboard initialized!", {
withAudio: true, withAudio: true,
src: getVoicePath('jankboard-initialized', 'en'), src: getVoicePath("jankboard-initialized"),
}) });
setTimeout(() => { setTimeout(() => {
if (get(settingsStore).goWoke) return if (get(settingsStore).goWoke) return;
Notifications.success('LittenOS is online', { Notifications.success("LittenOS is online", {
withAudio: true, withAudio: true,
src: getVoicePath('littenos-is-online', 'en'), src: getVoicePath("littenos-is-online"),
}) });
setTimeout(() => { setTimeout(() => {
Notifications.warn('Breaching Monte Vista codebase', { Notifications.warn("Breaching Monte Vista codebase", {
withAudio: true, withAudio: true,
src: getVoicePath('breaching-monte-vista', 'en'), src: getVoicePath("breaching-monte-vista"),
}) });
setTimeout(() => { setTimeout(() => {
Notifications.playAudio( Notifications.playAudio(getVoicePath("hello-virtual-assistant"), () => {
getVoicePath('hello-virtual-assistant', 'en'), sequenceStore.update("initializationComplete", true);
() => { periodicSequence();
sequenceStore.update('initializationComplete', true) });
periodicSequence() }, 3000);
} }, 3000);
) }, 3000);
}, 3000) };
}, 3000)
}, 3000)
}
let counter = 1 let counter = 1;
/** /**
* Special sequence that plays invokes itself periodically, started automatically * Special sequence that plays invokes itself periodically, started automatically
* at the end of the initializationSequence * at the end of the initializationSequence
@ -64,7 +61,7 @@ let counter = 1
* @return void * @return void
*/ */
const periodicSequence = async () => { const periodicSequence = async () => {
await tick() await tick();
/** /**
* Returns either true or false based on the provided probability * Returns either true or false based on the provided probability
@ -74,11 +71,11 @@ const periodicSequence = async () => {
*/ */
const chance = (probability: number) => { const chance = (probability: number) => {
if (probability < 0 || probability > 1) { if (probability < 0 || probability > 1) {
throw new Error('Probability must be between 0 and 1') throw new Error("Probability must be between 0 and 1");
} }
return Math.random() < probability * get(settingsStore).randomWeight return Math.random() < probability * get(settingsStore).randomWeight;
} };
/** /**
* Calls a callback function at regular intervals. * Calls a callback function at regular intervals.
@ -87,140 +84,140 @@ const periodicSequence = async () => {
* @param callback - the function to call * @param callback - the function to call
*/ */
const every = (seconds: number, callback: () => void) => { const every = (seconds: number, callback: () => void) => {
if (counter % seconds === 0) callback() if (counter % seconds === 0) callback();
} };
// add your periodic sequences here // add your periodic sequences here
every(15, () => { every(15, () => {
if (chance(0.2)) breaching1323Sequence() if (chance(0.2)) breaching1323Sequence();
else if (chance(0.2)) breaching254Sequence() else if (chance(0.2)) breaching254Sequence();
}) });
every(25, () => { every(25, () => {
if (chance(0.05)) bullyingRohanSequence() if (chance(0.05)) bullyingRohanSequence();
else if (chance(0.1)) bypassCoprocessorRestrictionsSequence() else if (chance(0.1)) bypassCoprocessorRestrictionsSequence();
}) });
// Dont touch // Dont touch
counter++ counter++;
setTimeout(periodicSequence, 1000) setTimeout(periodicSequence, 1000);
} };
export const criticalFailureIminentSequence = async () => { export const criticalFailureIminentSequence = async () => {
await tick() await tick();
Notifications.error('Critical robot failure imminent', { Notifications.error("Critical robot failure imminent", {
withAudio: true, withAudio: true,
src: getVoicePath('critical-robot-failure', 'en'), src: getVoicePath("critical-robot-failure"),
}) });
} };
export const collisionDetectedSequence = async () => { export const collisionDetectedSequence = async () => {
await tick() await tick();
Notifications.error('Collision detected', { Notifications.error("Collision detected", {
withAudio: true, withAudio: true,
src: getVoicePath('collision-detected', 'en'), src: getVoicePath("collision-detected"),
}) });
} };
export const collisionImminentSequence = async () => { export const collisionImminentSequence = async () => {
await tick() await tick();
Notifications.error('Collision imminent', { Notifications.error("Collision imminent", {
withAudio: true, withAudio: true,
src: getVoicePath('collision-imminent', 'en'), src: getVoicePath("collision-imminent"),
}) });
} };
export const cruiseControlEngagedSequence = async () => { export const cruiseControlEngagedSequence = async () => {
if (get(settingsStore).disableAnnoyances) return if (get(settingsStore).disableAnnoyances) return;
await tick() await tick();
Notifications.success('Cruise control engaged', { Notifications.success("Cruise control engaged", {
withAudio: true, withAudio: true,
src: getVoicePath('cruise-control-engaged', 'en'), src: getVoicePath("cruise-control-engaged"),
}) });
} };
export const retardSequence = async () => { export const retardSequence = async () => {
if (get(settingsStore).goWoke) return if (get(settingsStore).goWoke) return;
await tick() await tick();
Notifications.warn('Retard', { Notifications.warn("Retard", {
withAudio: true, withAudio: true,
src: getVoicePath('retard', 'en'), src: getVoicePath("retard"),
}) });
} };
const breaching254Sequence = async () => { const breaching254Sequence = async () => {
if (get(settingsStore).disableAnnoyances) return if (get(settingsStore).disableAnnoyances) return;
await tick() await tick();
Notifications.warn('Breaching 254 mainframe', { Notifications.warn("Breaching 254 mainframe", {
withAudio: true, withAudio: true,
src: getVoicePath('breaching-254-mainframe', 'en'), src: getVoicePath("breaching-254-mainframe"),
}) });
} };
const breaching1323Sequence = async () => { const breaching1323Sequence = async () => {
if (get(settingsStore).disableAnnoyances) return if (get(settingsStore).disableAnnoyances) return;
await tick() await tick();
Notifications.warn('Breaching 1323 mainframe', { Notifications.warn("Breaching 1323 mainframe", {
withAudio: true, withAudio: true,
src: getVoicePath('breaching-1323-mainframe', 'en'), src: getVoicePath("breaching-1323-mainframe"),
}) });
} };
const bullyingRohanSequence = async () => { const bullyingRohanSequence = async () => {
if (get(settingsStore).disableAnnoyances) return if (get(settingsStore).disableAnnoyances) return;
await tick() await tick();
Notifications.info('Bullying Rohan', { Notifications.info("Bullying Rohan", {
withAudio: true, withAudio: true,
src: getVoicePath('bullying-rohan', 'en'), src: getVoicePath("bullying-rohan"),
}) });
} };
export const userErrorDetectedSequence = async () => { export const userErrorDetectedSequence = async () => {
await tick() await tick();
Notifications.error('User error detected', { Notifications.error("User error detected", {
withAudio: true, withAudio: true,
src: getVoicePath('user-error-detected', 'en'), src: getVoicePath("user-error-detected"),
}) });
} };
// hacky way to prevent duplicate infotainment bootups // hacky way to prevent duplicate infotainment bootups
let infotainmentStarted = false let infotainmentStarted = false;
export const infotainmentBootupSequence = async () => { export const infotainmentBootupSequence = async () => {
if ( if (
get(sequenceStore).infotainmentStartedFirstTime || get(sequenceStore).infotainmentStartedFirstTime ||
get(settingsStore).disableAnnoyances || get(settingsStore).disableAnnoyances ||
infotainmentStarted infotainmentStarted
) )
return return;
infotainmentStarted = true infotainmentStarted = true;
await tick() await tick();
const sequence = () => { const sequence = () => {
Notifications.info('Infotainment system buffering', { Notifications.info("Infotainment system buffering", {
withAudio: true, withAudio: true,
src: getVoicePath('infotainment-system-buffering', 'en'), src: getVoicePath("infotainment-system-buffering"),
}) });
setTimeout(() => { setTimeout(() => {
Notifications.success('Infotainment system online', { Notifications.success("Infotainment system online", {
withAudio: true, withAudio: true,
src: getVoicePath('infotainment-system-online', 'en'), src: getVoicePath("infotainment-system-online"),
onComplete: () => { onComplete: () => {
sequenceStore.update('infotainmentStartedFirstTime', true) sequenceStore.update("infotainmentStartedFirstTime", true);
}, },
}) });
}, 3000) }, 3000);
} };
if (!get(sequenceStore).initializationComplete) { if (!get(sequenceStore).initializationComplete) {
const unsubscribe = sequenceStore.subscribe(data => { const unsubscribe = sequenceStore.subscribe((data) => {
if (data.initializationComplete) { if (data.initializationComplete) {
sequence() sequence();
unsubscribe() unsubscribe();
} }
}) });
} else { } else {
sequence() sequence();
} }
} };
/** /**
* Waits for the infotainment system to boot up before executing the given sequence. * Waits for the infotainment system to boot up before executing the given sequence.
@ -231,77 +228,77 @@ export const infotainmentBootupSequence = async () => {
*/ */
const waitForInfotainmentBootup = (sequence: () => void) => { const waitForInfotainmentBootup = (sequence: () => void) => {
if (!get(sequenceStore).infotainmentStartedFirstTime) { if (!get(sequenceStore).infotainmentStartedFirstTime) {
const unsubscribe = sequenceStore.subscribe(data => { const unsubscribe = sequenceStore.subscribe((data) => {
if (data.infotainmentStartedFirstTime) { if (data.infotainmentStartedFirstTime) {
sequence() sequence();
unsubscribe() unsubscribe();
} }
}) });
} else { } else {
sequence() sequence();
} }
} };
export const musicPlayerBootupSequence = async () => { export const musicPlayerBootupSequence = async () => {
if ( if (
get(sequenceStore).musicStartedFirstTime || get(sequenceStore).musicStartedFirstTime ||
get(settingsStore).disableAnnoyances get(settingsStore).disableAnnoyances
) )
return return;
await tick() await tick();
sequenceStore.update('musicStartedFirstTime', true) sequenceStore.update("musicStartedFirstTime", true);
waitForInfotainmentBootup(() => { waitForInfotainmentBootup(() => {
Notifications.info('Downloading copyrighted music...', { Notifications.info("Downloading copyrighted music...", {
withAudio: true, withAudio: true,
src: getVoicePath('downloading-copyrighted-music', 'en'), src: getVoicePath("downloading-copyrighted-music"),
}) });
}) });
} };
export const gbaEmulatorBootupSequence = async () => { export const gbaEmulatorBootupSequence = async () => {
if ( if (
get(sequenceStore).gbaEmulatorStartedFirstTime || get(sequenceStore).gbaEmulatorStartedFirstTime ||
get(settingsStore).disableAnnoyances get(settingsStore).disableAnnoyances
) )
return return;
await tick() await tick();
sequenceStore.update('gbaEmulatorStartedFirstTime', true) sequenceStore.update("gbaEmulatorStartedFirstTime", true);
waitForInfotainmentBootup(() => { waitForInfotainmentBootup(() => {
Notifications.info('Loading pirated Nintendo ROMs', { Notifications.info("Loading pirated Nintendo ROMs", {
withAudio: true, withAudio: true,
src: getVoicePath('loading-pirated-nintendo', 'en'), src: getVoicePath("loading-pirated-nintendo"),
}) });
}) });
} };
export const doomBootupSequence = async () => { export const doomBootupSequence = async () => {
if ( if (
get(sequenceStore).doomStartedFirstTime || get(sequenceStore).doomStartedFirstTime ||
get(settingsStore).disableAnnoyances get(settingsStore).disableAnnoyances
) )
return return;
await tick() await tick();
sequenceStore.update('doomStartedFirstTime', true) sequenceStore.update("doomStartedFirstTime", true);
waitForInfotainmentBootup(() => { waitForInfotainmentBootup(() => {
Notifications.success('Doom Engaged', { Notifications.success("Doom Engaged", {
withAudio: true, withAudio: true,
src: getVoicePath('doom-engaged', 'en'), src: getVoicePath("doom-engaged"),
}) });
}) });
} };
const bypassCoprocessorRestrictionsSequence = async () => { const bypassCoprocessorRestrictionsSequence = async () => {
if (get(settingsStore).disableAnnoyances) return if (get(settingsStore).disableAnnoyances) return;
await tick() await tick();
Notifications.warn('Bypassing coprocessor restrictions', { Notifications.warn("Bypassing coprocessor restrictions", {
withAudio: true, withAudio: true,
src: getVoicePath('bypassing-coprocessor-restrictions', 'en'), src: getVoicePath("bypassing-coprocessor-restrictions"),
}) });
} };

View file

@ -1,12 +1,15 @@
/* stores global app wide settings */ /* stores global app wide settings */
import { writable } from 'svelte/store' import { writable } from "svelte/store";
type SupportedLanguage = "en" | "rus";
export interface SettingsStoreData { export interface SettingsStoreData {
disableAnnoyances: boolean disableAnnoyances: boolean;
goWoke: boolean goWoke: boolean;
fastStartup: boolean fastStartup: boolean;
randomWeight: number randomWeight: number;
voiceLang: SupportedLanguage;
} }
export const defaults: SettingsStoreData = { export const defaults: SettingsStoreData = {
@ -14,25 +17,26 @@ export const defaults: SettingsStoreData = {
goWoke: false, // go woke (for showing parents or other officials where DEI has taken over), disables "offensive" sequences goWoke: false, // go woke (for showing parents or other officials where DEI has taken over), disables "offensive" sequences
fastStartup: false, // skip the loading splash screen (for development purposes. Setting this from within the app has no effect.) fastStartup: false, // skip the loading splash screen (for development purposes. Setting this from within the app has no effect.)
randomWeight: 1, // the weight of random events (multiplied by the original probability) randomWeight: 1, // the weight of random events (multiplied by the original probability)
} voiceLang: "en",
};
const createSequenceStore = () => { const createSequenceStore = () => {
const { subscribe, set, update } = writable<SettingsStoreData>(defaults) const { subscribe, set, update } = writable<SettingsStoreData>(defaults);
return { return {
subscribe, subscribe,
update: ( update: (
data: keyof SettingsStoreData, data: keyof SettingsStoreData,
newValue: SettingsStoreData[typeof data] newValue: SettingsStoreData[typeof data]
) => { ) => {
update(store => { update((store) => {
// @ts-expect-error // @ts-expect-error
store[data] = newValue store[data] = newValue;
return store return store;
}) });
}, },
reset: () => set(defaults), reset: () => set(defaults),
set: (data: SettingsStoreData) => set(data), set: (data: SettingsStoreData) => set(data),
} };
} };
export const settingsStore = createSequenceStore() export const settingsStore = createSequenceStore();

View file

@ -1,3 +1,6 @@
import { get } from "svelte/store";
import { settingsStore } from "../stores/settingsStore";
/** /**
* Retrieves the voice audio path for the given audio file. * Retrieves the voice audio path for the given audio file.
* *
@ -5,7 +8,18 @@
* @param lang - the language of the audio * @param lang - the language of the audio
* @return the path of the audio file * @return the path of the audio file
*/ */
type SupportedLanguage = 'en' | 'rus' type SupportedLanguage = "en" | "rus";
export default function getVoicePath(audio: string, lang: SupportedLanguage) {
return `/static/voices/${lang}/${audio}.wav` let currentLang = "en";
settingsStore.subscribe((data) => {
currentLang = data.voiceLang;
});
export default function getVoicePath(audio: string, lang?: SupportedLanguage) {
console.log(get(settingsStore).voiceLang);
if (!lang) {
return `/static/voices/${get(settingsStore).voiceLang}/${audio}.wav`;
}
return `/static/voices/${lang}/${audio}.wav`;
} }