This commit is contained in:
polv committed 2021-10-25 11:05:38 +07:00
1 parent 7d5114953b
commit cbc36d19f5
7 files changed
+215 -194

No files matched your search

+5 -4
View File
@@ -17,13 +17,15 @@ export async function speak(
opts: {
lang?: string
forceOffline?: boolean
url?: string
} = {}
) {
if (!opts.forceOffline) {
const audio = new Audio(
`/api/tts?q=${encodeURIComponent(s)}&lang=${encodeURIComponent(
opts.lang || 'ja'
)}`
opts.url ||
`/api/tts?q=${encodeURIComponent(s)}&lang=${encodeURIComponent(
opts.lang || 'ja'
)}`
)
await audio.play().catch(() =>
speak(s, {
@@ -73,7 +75,6 @@ window.addEventListener('keydown', (ev) => {
}
if (ev.key === 's') {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const s = window.getSelection()!.toString()
if (s) {
speak(s)