Add speech synthesis
This commit is contained in:
18
src/API.ts
18
src/API.ts
@ -1287,6 +1287,24 @@ export class UserAPI {
|
|||||||
|
|
||||||
abs = Math.abs;
|
abs = Math.abs;
|
||||||
|
|
||||||
|
|
||||||
|
// =============================================================
|
||||||
|
// Speed synthesis
|
||||||
|
// =============================================================
|
||||||
|
|
||||||
|
speak = (text: string, index: number): void => {
|
||||||
|
/*
|
||||||
|
* Speaks the given text using the browser's speech synthesis API.
|
||||||
|
* @param text - The text to speak
|
||||||
|
* @param index - The index of the voice to use
|
||||||
|
*/
|
||||||
|
const synth = window.speechSynthesis;
|
||||||
|
synth.cancel();
|
||||||
|
const utterance = new SpeechSynthesisUtterance(text);
|
||||||
|
utterance.voice = speechSynthesis.getVoices()[index];
|
||||||
|
synth.speak(utterance);
|
||||||
|
}
|
||||||
|
|
||||||
// =============================================================
|
// =============================================================
|
||||||
// Trivial functions
|
// Trivial functions
|
||||||
// =============================================================
|
// =============================================================
|
||||||
|
|||||||
@ -1577,6 +1577,27 @@ mod(0.25) :: sound('sine')
|
|||||||
|
|
||||||
**Note:** you can also set the _modulation index_ and the _harmonic ratio_ with the <icode>fm</icode> argument. You will have to feed both as a string: <icode>fm('2:4')</icode>. If you only feed one number, only the _modulation index_ will be updated.
|
**Note:** you can also set the _modulation index_ and the _harmonic ratio_ with the <icode>fm</icode> argument. You will have to feed both as a string: <icode>fm('2:4')</icode>. If you only feed one number, only the _modulation index_ will be updated.
|
||||||
|
|
||||||
|
# Speech synthesis
|
||||||
|
|
||||||
|
Topos can also speak using [Web Speec API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Speech_API)!
|
||||||
|
|
||||||
|
${makeExample(
|
||||||
|
"Hello world!",
|
||||||
|
`
|
||||||
|
mod(4) :: speak("Hello world!")
|
||||||
|
`,
|
||||||
|
false
|
||||||
|
)}
|
||||||
|
|
||||||
|
${makeExample(
|
||||||
|
"Speak with a different voice",
|
||||||
|
`
|
||||||
|
mod(2) :: speak("Topos!",irand(0,25))
|
||||||
|
`,
|
||||||
|
false
|
||||||
|
)}
|
||||||
|
|
||||||
|
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const about: string = `
|
const about: string = `
|
||||||
|
|||||||
Reference in New Issue
Block a user