Skip to content

Instantly share code, notes, and snippets.

@kawaz
Last active December 12, 2023 08:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kawaz/b68c0efc87dc074ef27be3ed01bf84d0 to your computer and use it in GitHub Desktop.
Save kawaz/b68c0efc87dc074ef27be3ed01bf84d0 to your computer and use it in GitHub Desktop.
読み上げAPIのテスト
// 日本語の声をランダムに1つ選ぶ
const voices = speechSynthesis.getVoices().filter(v=>/^ja-/.test(v.lang))
const voice = voices[Math.floor(voices.length*100000*Math.random())%voices.length]
const ssu = new SpeechSynthesisUtterance()
ssu.lang = 'ja-JP' // 言語
ssu.voice = voice // 発話に使用する音声(未設定の場合lang設定を見て適切な音声が選ばれる
ssu.volume = 1 // 発話の音量 0~1、default=1
ssu.rate = 1 // 発話の速度 0.1~10、default=1
ssu.pitch = 1 // 発話の音程 0~2、default=1
ssu.text = 'こんにちは' // 発話合成したいテキストそのものまたはSSML
window.speechSynthesis.speak(ssu)
@kawaz
Copy link
Author

kawaz commented Dec 12, 2023

音声認識のサンプルはこちら
https://gist.github.com/kawaz/ece40ab50d2ae0c1f888bb7c6f6cef72

音声合成のサンプルはこちら
https://gist.github.com/kawaz/b68c0efc87dc074ef27be3ed01bf84d0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment