Add speech as string prototype

This commit is contained in:
2023-08-30 22:08:23 +03:00
parent 4098ea6e50
commit db2434d4dc
4 changed files with 130 additions and 10 deletions

View File

@ -1581,6 +1581,16 @@ mod(0.25) :: sound('sine')
Topos can also speak using [Web Speec API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Speech_API)!
Speech synthesis can be used in two ways:
- <icode>speak(text: string, voice: number, rate: number, pitch: number)</icode>: speak the given text.
Or by using string and chaining:
- <icode>"Hello".rate(1.5).pitch(0.5).speak()</icode>.
Examples:
${makeExample(
"Hello world!",
`
@ -1590,13 +1600,36 @@ mod(4) :: speak("Hello world!")
)}
${makeExample(
"Speak with a different voice",
"Different voices",
`
mod(2) :: speak("Topos!",irand(0,25))
`,
false
)}
${makeExample(
"Chaining string",
`
onbeat(1,3) :: "Foobaba".voice(irand(0,10)).speak()
`,
false
)}
${makeExample(
"Building string and chaining",
`
const subject = ["coder","user","loser"].pick()
const verb = ["is", "was", "isnt"].pick()
const object = ["happy","sad","tired"].pick()
const sentence = subject+" "+verb+" "+" "+object
mod(6) :: sentence.pitch(0).rate(0).voice([0,2].pick()).say()
`,
false
)}
`;