- This article is about the Text to Speech block. For the looks block, see Say () (block).
Speak () | |
speak () | |
Category | Text to Speech |
Type | Stack |
Introduced in | 3.0 |
The speak () block is a stack block and a Text to Speech block. The block uses the text to speech tool to speak the given text. It will speak the selected voice with the language selected in the Set Language to () block.
The block requires a connection to the internet in order to function unless the voice is set to "kitten", as the block uses the Amazon Polly API to speak.
Limitations
Usage of the block is limited to 128 characters. If a string longer than 128 characters is given, then only the first 128 characters will be spoken.[1]
If you would like to speak text that is longer than 128 characters, you can use the following script: This script basically splits up the text that needs to be said into different shorter sections. Because one wouldn't want to split up two different speak blocks in the middle of a word, one has the option to give the length of the longest word that will be used. If left blank, it defaults to 0 (which means words will be split up).
define say [text] longest WORD possible [# of letters]::custom set [rep at a time v] to ((127)-(# of letters)) if <(# of letters)=()> then set [rep at a time v] to (128) end if <not<(# of letters)<(128)>> then set [rep at a time v] to (128) end if <(# of letters)<(0)> then set [rep at a time v] to (128) end if <((length of (text)) mod (rep at a time)) = (0)> then set [total reps v] to ([floor v] of ((length of (text))/(rep at a time))) else set [total reps v] to ([floor v] of (((length of (text))/(rep at a time))+(1)) end set [rep # v] to (0) repeat (total reps) set [i v] to ((0)+((rep #)*(rep at a time))) set [speak text v] to () repeat (rep at a time) change [i v] by (1) set [speak text v] to (join(speak text)(letter(i)of(text) end speak (speak text) change [rep # v] by (1) end
Uses
In simple animations:
when green flag clicked say [Hello]:: custom define say (sentence) say (sentence) speak (sentence)
A non-player character in an RPG:
when Green Flag clicked forever if <(distance to (player v)) < [50]> then speak [hello there] wait until <not<(distance to (player v)) < [50]>> end end
Speaking text in a different language:
when green flag clicked set language to (language::variables) speak (translate [Hello] to (language::variables))
Speaking text with a different voice:
when green flag clicked set voice to (giant v) speak [Hello]
Bad Word Detection
Similar to the Translate () to () block, a bad word detector is present. When a user attempts to input a bad word and clicks the block, no words will be spoken unless the voice is set to "kitten". Additionally, all bad English words will not said regardless of language, although bad words in other languages will only not be said when that language is chosen.