Skip to content

Commit

Permalink
feat: speech recognition language toggle
Browse files Browse the repository at this point in the history
feat: add lazy help message
chore: use <link> for `style.css`
  • Loading branch information
sglkc committed Nov 29, 2022
1 parent bcb059a commit 118e697
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<script src="scripts/live2d.min.js" defer></script>
<script src="scripts/live2dcubismcore.min.js" defer></script>
<link rel="icon" type="image/png" href="favicon.png">
<link rel="stylesheet" href="style.css">
</head>
<body>
<main id="container">
Expand All @@ -27,6 +28,7 @@
<button id="recognition">
<img width="40" height="40">
</button>
<button id="recognition-lang">EN</button>
</nav>
<canvas id="canvas"></canvas>
<img id="background" src="assets/background.webp" alt="background" draggable="false">
Expand Down
6 changes: 6 additions & 0 deletions src/style.css → public/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ html, body {
transform: rotate(10deg) scale(1.1);
}

#recognition-lang {
font-size: 2rem;
font-weight: bold;
color: white;
}

#canvas {
position: fixed;
bottom: 0;
Expand Down
20 changes: 20 additions & 0 deletions src/SpeechRecognition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const SpeechRecognition = InitRecognition

const img = <HTMLImageElement>document.querySelector('#recognition > img');
const button = <HTMLButtonElement>document.querySelector('#recognition');
const lang = <HTMLButtonElement>document.querySelector('#recognition-lang');
const input = <HTMLInputElement>document.getElementById('message');
const send = <HTMLInputElement>document.getElementById('send');

Expand All @@ -25,6 +26,25 @@ button.onclick = () => {

img.src = SpeechRecognition.unsupported ? MicMute : Mic;

lang.onclick = () => {
if (SpeechRecognition.unsupported) return;

switch (SpeechRecognition.lang) {
case 'en-US':
SpeechRecognition.lang = 'id-ID';
lang.innerText = 'ID';
break;
case 'id-ID':
SpeechRecognition.lang = 'ja-JP';
lang.innerText = 'JA';
break;
case 'ja-JP':
default:
SpeechRecognition.lang = 'en-US';
lang.innerText = 'EN';
}
}

SpeechRecognition.continuous = true;
SpeechRecognition.interimResults = true;
SpeechRecognition.lang = 'en-US';
Expand Down
20 changes: 19 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import './style.css';
import { CustomWindow } from './types';
import Live2D from './Live2D';
import './Message.ts';
Expand All @@ -14,3 +13,22 @@ window.Modules = {
};

document.getElementById('loader')!.style.display = 'none';

// TODO: better help pleasze
document.getElementById('help')!.onclick = () => alert(
'The laziest type of help you\'ve ever seen.\n' +
'\n' +
'> Languages <\n' +
'Chiai can speak 3 languages! English, Bahasa Indonesia, and Japanese. She ' +
'can guess what language you\'re using and she\'ll respond in that language.\n' +
'\n' +
'> Speech Recognition <\n' +
'Click the mic button and start speaking! Speech output will be displayed on ' +
'the message input box and will be sent automatically once you stopped recording.\n' +
'NOTE: Speech Recognition is not supported on all browsers, so don\'t expect it ' +
'to work.\n' +
'\n' +
'> Anything else <\n' +
'For more information, you could visit this project\'s repository by clicking ' +
'the GitHub button, and scroll down.'
);

0 comments on commit 118e697

Please sign in to comment.