mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2026-01-07 07:54:04 +08:00
moved tts into its own file, added support for bcp47 codes to enable multilanguage. closes #397
This commit is contained in:
parent
214fe571f8
commit
653ae1193c
5 changed files with 42 additions and 8 deletions
|
|
@ -179,6 +179,7 @@ const refactoredSrc = [
|
|||
"./src/js/test/today-tracker.js",
|
||||
"./src/js/test/weak-spot.js",
|
||||
"./src/js/test/wordset.js",
|
||||
"./src/js/test/tts.js",
|
||||
"./src/js/replay.js",
|
||||
];
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ import * as CommandlineLists from "./commandline-lists";
|
|||
import * as BackgroundFilter from "./custom-background-filter";
|
||||
import LayoutList from "./layouts";
|
||||
import * as ChallengeContoller from "./challenge-controller";
|
||||
import * as TTS from "./tts";
|
||||
|
||||
export let localStorageConfig = null;
|
||||
export let dbConfigLoaded = false;
|
||||
|
|
@ -339,8 +340,14 @@ export function setFavThemes(themes, nosave) {
|
|||
}
|
||||
|
||||
export function setFunbox(funbox, nosave) {
|
||||
config.funbox = funbox ? funbox : "none";
|
||||
let val = funbox ? funbox : "none";
|
||||
config.funbox = val;
|
||||
ChallengeContoller.clearActive();
|
||||
if (val === "none") {
|
||||
TTS.clear();
|
||||
} else if (val === "tts") {
|
||||
TTS.init();
|
||||
}
|
||||
if (!nosave) {
|
||||
saveToLocalStorage();
|
||||
}
|
||||
|
|
@ -1332,6 +1339,9 @@ export function setLanguage(language, nosave) {
|
|||
language = "english";
|
||||
}
|
||||
config.language = language;
|
||||
if (config.funbox === "tts") {
|
||||
TTS.setLanguage();
|
||||
}
|
||||
try {
|
||||
firebase.analytics().logEvent("changedLanguage", {
|
||||
language: language,
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import * as Misc from "./misc";
|
|||
import * as ManualRestart from "./manual-restart-tracker";
|
||||
import Config, * as UpdateConfig from "./config";
|
||||
import * as Settings from "./settings";
|
||||
import * as TTS from "./tts";
|
||||
|
||||
let modeSaved = null;
|
||||
let memoryTimer = null;
|
||||
|
|
@ -79,13 +80,7 @@ export function reset() {
|
|||
|
||||
export function toggleScript(...params) {
|
||||
if (Config.funbox === "tts") {
|
||||
var msg = new SpeechSynthesisUtterance();
|
||||
console.log("Speaking");
|
||||
msg.text = params[0];
|
||||
if (!msg.text) return;
|
||||
msg.lang = "en-US";
|
||||
window.speechSynthesis.cancel();
|
||||
window.speechSynthesis.speak(msg);
|
||||
TTS.speak(params[0]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
27
src/js/test/tts.js
Normal file
27
src/js/test/tts.js
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import Config from "./config";
|
||||
import * as Misc from "./misc";
|
||||
|
||||
let voice;
|
||||
|
||||
export async function init() {
|
||||
voice = new SpeechSynthesisUtterance();
|
||||
setLanguage();
|
||||
}
|
||||
|
||||
export function clear() {
|
||||
voice = undefined;
|
||||
}
|
||||
|
||||
export async function setLanguage(lang = Config.language) {
|
||||
if (!voice) return;
|
||||
let language = await Misc.getLanguage(lang);
|
||||
let bcp = language.bcp47 ? language.bcp47 : "en-US";
|
||||
voice.lang = bcp;
|
||||
}
|
||||
|
||||
export function speak(text) {
|
||||
if (!voice) init();
|
||||
voice.text = text;
|
||||
window.speechSynthesis.cancel();
|
||||
window.speechSynthesis.speak(voice);
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
{
|
||||
"name": "polish",
|
||||
"leftToRight": true,
|
||||
"bcp47": "pl-PL",
|
||||
"words": [
|
||||
"jak",
|
||||
"jego",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue