Difference between revisions of "Manual:Text to Speech Functions"
Jump to navigation
Jump to search
m (→ttsPauseSpeech: attribute source) |
|||
(31 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
{{TOC right}} | {{TOC right}} | ||
+ | {{#description2:Mudlet API documentation for functions which can make Mudlet talk for you (audible sound from written words).}} | ||
= Text to Speech Functions = | = Text to Speech Functions = | ||
− | These functions can make Mudlet talk for you (audible sound from written words) | + | These functions can make Mudlet talk for you (audible sound from written words). Check out the [[Manual:Text-to-Speech|Text-To-Speech Manual]] for more detail on how this all works together. |
+ | |||
+ | {{MudletVersion|3.17}} | ||
Several [[Manual:Event_Engine|Mudlet events]] are available functionality as well: | Several [[Manual:Event_Engine|Mudlet events]] are available functionality as well: | ||
Line 10: | Line 13: | ||
* ttsSpeechPaused | * ttsSpeechPaused | ||
* ttsSpeechError | * ttsSpeechError | ||
− | + | * ttsPitchChanged | |
+ | * ttsRateChanged | ||
+ | * ttsVoiceChanged | ||
+ | * ttsVolumeChanged | ||
==ttsClearQueue== | ==ttsClearQueue== | ||
Line 17: | Line 23: | ||
: Returns false if an invalid index is given. | : Returns false if an invalid index is given. | ||
− | See also: | + | : See also: [[#ttsGetQueue|ttsGetQueue]], [[#ttsQueue|ttsQueue]] |
− | [[# | ||
;Parameters | ;Parameters | ||
Line 24: | Line 29: | ||
: (optional) number. The text at this index position of the queue will be removed. If no number is given, the whole queue is cleared. | : (optional) number. The text at this index position of the queue will be removed. If no number is given, the whole queue is cleared. | ||
− | {{ | + | {{MudletVersion|3.17}} |
;Example | ;Example | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
− | -- queue five words and then remove "two" | + | -- queue five words and then remove some, "one, two, four" will be actually said |
− | + | ttsQueue("One") | |
− | + | ttsQueue("Two") | |
− | + | ttsQueue("Three") | |
− | + | ttsQueue("Four") | |
− | + | ttsQueue("Five") | |
ttsClearQueue(2) | ttsClearQueue(2) | ||
ttsClearQueue(3) | ttsClearQueue(3) | ||
Line 48: | Line 53: | ||
See also: | See also: | ||
[[#ttsSpeak|ttsSpeak]], | [[#ttsSpeak|ttsSpeak]], | ||
− | [[# | + | [[#ttsQueue|ttsQueue]] |
− | {{ | + | {{MudletVersion|3.17}} |
+ | ;Example | ||
+ | <syntaxhighlight lang="lua"> | ||
+ | ttsQueue("One") | ||
+ | ttsQueue("Two") | ||
+ | ttsQueue("Three") | ||
+ | ttsQueue("Four") | ||
+ | ttsQueue("Five") | ||
− | + | -- print the line currently spoken 1s and 3s after which will be "two" and "five" | |
− | -- print the line currently spoken | + | tempTimer(1, function() |
− | echo(ttsGetCurrentLine()) | + | echo("Speaking: ".. ttsGetCurrentLine().."\n") |
+ | end) | ||
+ | |||
+ | tempTimer(3, function() | ||
+ | echo("Speaking: ".. ttsGetCurrentLine().."\n") | ||
+ | end) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 66: | Line 83: | ||
[[#ttsGetVoices|ttsGetVoices]] | [[#ttsGetVoices|ttsGetVoices]] | ||
− | {{ | + | {{MudletVersion|3.17}} |
;Example | ;Example | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
-- for example returns "Microsoft Zira Desktop" on Windows (US locale) | -- for example returns "Microsoft Zira Desktop" on Windows (US locale) | ||
− | ttsGetCurrentVoice() | + | display(ttsGetCurrentVoice()) |
</syntaxhighlight> | </syntaxhighlight> | ||
+ | ==ttsGetPitch== | ||
+ | ;ttsGetPitch() | ||
+ | : If you want to analyse the pitch or tone of your current speech. | ||
+ | : Returns the current pitch as a number between 1 (high) and -1 (deep). | ||
− | == | + | See also: |
− | ; | + | [[#ttsSetPitch|ttsSetPitch]] |
+ | |||
+ | {{MudletVersion|3.17}} | ||
+ | |||
+ | ;Example | ||
+ | <syntaxhighlight lang="lua"> | ||
+ | local pitch = ttsGetPitch() | ||
+ | echo(pitch) | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | ==ttsGetQueue== | ||
+ | ;ttsGetQueue([index]) | ||
: This function can be used to show your current queue of texts, or any single text thereof. | : This function can be used to show your current queue of texts, or any single text thereof. | ||
: Returns a single text or a table of texts, or false. See index parameter for details. | : Returns a single text or a table of texts, or false. See index parameter for details. | ||
See also: | See also: | ||
− | [[# | + | [[#ttsQueue|ttsQueue]] |
;Parameters | ;Parameters | ||
Line 87: | Line 119: | ||
: (optional) number. The text at this index position of the queue will be returned. If no index is given, the whole queue will be returned. If the given index does not exist, the function returns false. | : (optional) number. The text at this index position of the queue will be returned. If no index is given, the whole queue will be returned. If the given index does not exist, the function returns false. | ||
− | {{ | + | {{MudletVersion|3.17}} |
;Example | ;Example | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
− | + | ttsQueue("We begin with some text") | |
− | + | ttsQueue("And we continue it without interruption") | |
− | display( | + | display(ttsGetQueue()) |
− | -- will show the queued texts as follows: | + | -- will show the queued texts as follows |
+ | -- (first line ignored because it's being spoken and is not in queue): | ||
-- { | -- { | ||
− | |||
-- "And we continue it without interruption" | -- "And we continue it without interruption" | ||
-- } | -- } | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | ==ttsGetRate== | ||
+ | ;ttsGetRate() | ||
+ | : If you want to analyse the rate or speed of your current speech. | ||
+ | : Returns the current rate as a number between 1 (fast) and -1 (slow). | ||
+ | |||
+ | See also: | ||
+ | [[#ttsSetRate|ttsSetRate]] | ||
+ | |||
+ | {{MudletVersion|3.17}} | ||
+ | |||
+ | ;Example | ||
+ | <syntaxhighlight lang="lua"> | ||
+ | local rate = ttsGetRate() | ||
+ | echo(rate) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
==ttsGetState== | ==ttsGetState== | ||
− | ; | + | ;ttsGetState() |
: With this function you can find the current state of the speech engine. | : With this function you can find the current state of the speech engine. | ||
: Returns one of: ttsSpeechReady, ttsSpeechPaused, ttsSpeechStarted, ttsSpeechError, ttsUnknownState. | : Returns one of: ttsSpeechReady, ttsSpeechPaused, ttsSpeechStarted, ttsSpeechError, ttsUnknownState. | ||
Line 108: | Line 156: | ||
See also: | See also: | ||
[[#ttsSpeak|ttsSpeak]], | [[#ttsSpeak|ttsSpeak]], | ||
− | [[# | + | [[#ttsPause|ttsPause]], |
− | [[# | + | [[#ttsResume|ttsResume]], |
− | [[# | + | [[#ttsQueue|ttsQueue]] |
− | {{ | + | {{MudletVersion|3.17}} |
;Example | ;Example | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
− | + | ttsQueue("We begin with some text") | |
+ | ttsQueue("And we continue it without interruption") | ||
echo(ttsGetState()) | echo(ttsGetState()) | ||
-- ttsSpeechStarted | -- ttsSpeechStarted | ||
Line 131: | Line 180: | ||
[[#ttsSetVoiceByIndex|ttsSetVoiceByIndex]] | [[#ttsSetVoiceByIndex|ttsSetVoiceByIndex]] | ||
− | {{ | + | {{MudletVersion|3.17}} |
;Example | ;Example | ||
Line 142: | Line 191: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | ==ttsGetVolume== | ||
+ | ;ttsGetVolume() | ||
+ | : If you want to analyse the volume of your current speech. | ||
+ | : Returns the current volume as a number between 1 (loud) and 0 (quiet). | ||
+ | |||
+ | See also: | ||
+ | [[#ttsSetVolume|ttsSetVolume]] | ||
+ | |||
+ | {{MudletVersion|3.17}} | ||
+ | |||
+ | ;Example | ||
+ | <syntaxhighlight lang="lua"> | ||
+ | local volume = ttsGetVolume() | ||
+ | echo(volume) | ||
+ | </syntaxhighlight> | ||
− | == | + | ==ttsPause== |
− | ; | + | ;ttsPause() |
− | : Pauses the speech which is currently spoken, if any. | + | : Pauses the speech which is currently spoken, if any. Engines on different OS's (Windows/macOS/Linux) behave differently - pause may not work at all, it may take several seconds before it takes effect, or it may pause instantly. Some engines will look for a break that they can later resume from, such as a sentence end. |
See also: | See also: | ||
− | [[# | + | [[#ttsResume|ttsResume]], |
− | [[# | + | [[#ttsQueue|ttsQueue]] |
− | {{ | + | {{MudletVersion|3.17}} |
+ | ;Example | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
-- set some text to be spoken, pause it 2s later, and unpause 4s later | -- set some text to be spoken, pause it 2s later, and unpause 4s later | ||
ttsSpeak("Sir David Frederick Attenborough is an English broadcaster and naturalist. He is best known for writing and presenting, in conjunction with the BBC Natural History Unit, the nine natural history documentary series that form the Life collection, which form a comprehensive survey of animal and plant life on Earth. Source: Wikipedia") | ttsSpeak("Sir David Frederick Attenborough is an English broadcaster and naturalist. He is best known for writing and presenting, in conjunction with the BBC Natural History Unit, the nine natural history documentary series that form the Life collection, which form a comprehensive survey of animal and plant life on Earth. Source: Wikipedia") | ||
− | tempTimer(2, function() | + | tempTimer(2, function() ttsPause() end) |
− | tempTimer(2, function() | + | tempTimer(2, function() ttsResume() end) |
</syntaxhighlight> | </syntaxhighlight> | ||
− | == | + | ==ttsQueue== |
− | ; | + | ;ttsQueue(text to queue, [index]) |
: This function will add the given text to your speech queue. Text from the queue will be spoken one after the other. This is opposed to ttsSpeak which will interrupt any spoken text immediately. The queue can be reviewed and modified, while their content has not been spoken. | : This function will add the given text to your speech queue. Text from the queue will be spoken one after the other. This is opposed to ttsSpeak which will interrupt any spoken text immediately. The queue can be reviewed and modified, while their content has not been spoken. | ||
See also: | See also: | ||
− | [[# | + | [[#ttsGetQueue|ttsGetQueue]], |
− | [[# | + | [[#ttsPause|ttsPause]], |
− | [[# | + | [[#ttsResume|ttsResume]], |
[[#ttsClearQueue|ttsClearQueue]], | [[#ttsClearQueue|ttsClearQueue]], | ||
[[#ttsGetState|ttsGetState]], | [[#ttsGetState|ttsGetState]], | ||
Line 179: | Line 244: | ||
: (optional) number. The text will be inserted to the queue at this index position. If no index is provided, the text will be added to the end of the queue. | : (optional) number. The text will be inserted to the queue at this index position. If no index is provided, the text will be added to the end of the queue. | ||
− | {{ | + | {{MudletVersion|3.17}} |
;Example | ;Example | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
− | + | ttsQueue("We begin with some text") | |
− | + | ttsQueue("And we continue it without interruption") | |
− | display( | + | display(ttsGetQueue()) |
− | -- | + | -- will show the queued texts as follows |
− | -- | + | -- (first line ignored because it's being spoken and is not in queue): |
-- { | -- { | ||
− | -- | + | -- "And we continue it without interruption" |
− | |||
-- } | -- } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | ==ttsResume== | |
− | == | + | ;ttsResume() |
− | ; | ||
: Resumes the speech which was previously spoken, if any has been paused. | : Resumes the speech which was previously spoken, if any has been paused. | ||
See also: | See also: | ||
− | [[# | + | [[#ttsPause|ttsPause]], |
− | [[# | + | [[#ttsQueue|ttsQueue]] |
− | {{ | + | {{MudletVersion|3.17}} |
+ | ;Example | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
-- set some text to be spoken, pause it 2s later, and unpause 4s later | -- set some text to be spoken, pause it 2s later, and unpause 4s later | ||
− | ttsSpeak("Sir David Frederick Attenborough is an English broadcaster and naturalist. He is best known for writing and presenting, in conjunction with the BBC Natural History Unit, the nine natural history documentary series that form the Life collection, which form a comprehensive survey of animal and plant life on Earth.") | + | ttsSpeak("Sir David Frederick Attenborough is an English broadcaster and naturalist. He is best known for writing and presenting, in conjunction with the BBC Natural History Unit, the nine natural history documentary series that form the Life collection, which form a comprehensive survey of animal and plant life on Earth. Source: Wikipedia") |
− | tempTimer(2, function() | + | tempTimer(2, function() ttsPause() end) |
− | tempTimer( | + | tempTimer(4, function() ttsResume() end) |
</syntaxhighlight> | </syntaxhighlight> | ||
Line 218: | Line 282: | ||
See also: | See also: | ||
− | [[# | + | [[#ttsQueue|ttsQueue]] |
;Parameters | ;Parameters | ||
Line 224: | Line 288: | ||
: Any written text which you would like to hear spoken to you. You can write literal text, or put in string variables, maybe taken from triggers or aliases, etc. | : Any written text which you would like to hear spoken to you. You can write literal text, or put in string variables, maybe taken from triggers or aliases, etc. | ||
− | {{ | + | {{MudletVersion|3.17}} |
;Example | ;Example | ||
Line 231: | Line 295: | ||
-- if 'target' is your target variable, you can also do this: | -- if 'target' is your target variable, you can also do this: | ||
− | ttsSpeak(" | + | ttsSpeak("Hello "..target) |
</syntaxhighlight> | </syntaxhighlight> | ||
− | == | + | ==ttsSetPitch== |
− | ; | + | ;ttsSetPitch(pitch) |
− | : Sets the pitch of speech playback. | + | : Sets the pitch or tone of speech playback. |
;Parameters | ;Parameters | ||
Line 242: | Line 306: | ||
: Number. Should be between 1 and -1, will be limited otherwise. | : Number. Should be between 1 and -1, will be limited otherwise. | ||
− | {{ | + | {{MudletVersion|3.17}} |
;Example | ;Example | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
− | + | -- talk deeply first, after 2 seconds talk highly, after 4 seconds normally again | |
− | + | ttsSetPitch(-1) | |
+ | ttsQueue("Deep voice") | ||
tempTimer(2, function() | tempTimer(2, function() | ||
− | + | ttsSetPitch(1) | |
− | + | ttsQueue("High voice") | |
end) | end) | ||
tempTimer(4, function() | tempTimer(4, function() | ||
− | + | ttsSetPitch(0) | |
− | + | ttsQueue("Normal voice") | |
end) | end) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | ==ttsSetRate== | |
− | == | + | ;ttsSetRate(rate) |
− | ; | + | : Sets the rate or speed of speech playback. On macOS and Windows, adjusting the system rate adjusts this value automatically. |
− | : Sets the rate of speech playback. | ||
;Parameters | ;Parameters | ||
Line 269: | Line 333: | ||
: Number. Should be between 1 and -1, will be limited otherwise. | : Number. Should be between 1 and -1, will be limited otherwise. | ||
− | {{ | + | {{MudletVersion|3.17}} |
;Example | ;Example | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
− | + | -- talk slowly first, after 2 seconds talk quickly, after 4 seconds normally again | |
− | + | ttsSetRate(-1) | |
+ | ttsQueue("Slow voice") | ||
tempTimer(2, function () | tempTimer(2, function () | ||
− | + | ttsSetRate(1) | |
− | + | ttsQueue("Quick voice") | |
end) | end) | ||
− | tempTimer( | + | tempTimer(4, function () |
− | + | ttsSetRate(0) | |
− | + | ttsQueue("Normal voice") | |
end) | end) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | ==ttsSetVolume== | |
− | == | + | ;ttsSetVolume(volume) |
− | ; | + | : Sets the volume of speech playback. On macOS, adjusting the system rate adjusts this value automatically. |
− | : Sets the volume of speech playback. | ||
;Parameters | ;Parameters | ||
Line 296: | Line 360: | ||
: Number. Should be between 1 and 0, will be limited otherwise. | : Number. Should be between 1 and 0, will be limited otherwise. | ||
− | {{ | + | {{MudletVersion|3.17}} |
;Example | ;Example | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
− | + | -- talk quietly first, after 2 seconds talk a bit louder, after 4 seconds normally again | |
+ | ttsSetVolume(0.2) | ||
ttsSpeak("Quiet voice") | ttsSpeak("Quiet voice") | ||
tempTimer(2, function () | tempTimer(2, function () | ||
− | + | ttsSetVolume(0.5) | |
ttsSpeak("Low voice") | ttsSpeak("Low voice") | ||
end) | end) | ||
− | tempTimer( | + | tempTimer(4, function () |
− | + | ttsSetVolume(1) | |
ttsSpeak("Normal voice") | ttsSpeak("Normal voice") | ||
end) | end) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | |||
==ttsSetVoiceByIndex== | ==ttsSetVoiceByIndex== | ||
;ttsSetVoiceByIndex(index) | ;ttsSetVoiceByIndex(index) | ||
− | : If you have multiple voices available, you can switch them with this function by giving their index position as seen in the table you receive from ttsGetVoices(). If you know their name, you can also use ttsSetVoiceByName. | + | : If you have multiple voices available, you can switch them with this function by giving their index position as seen in the table you receive from ttsGetVoices(). If you know their name, you can also use ttsSetVoiceByName. On macOS and Windows, adjusting the system voice adjusts this value automatically. |
: Returns true, if the setting was successful, errors otherwise. | : Returns true, if the setting was successful, errors otherwise. | ||
Line 327: | Line 391: | ||
: Number. The voice from this index position of the ttsGetVoices table will be set. | : Number. The voice from this index position of the ttsGetVoices table will be set. | ||
− | {{ | + | {{MudletVersion|3.17}} |
;Example | ;Example | ||
Line 333: | Line 397: | ||
display(ttsGetVoices()) | display(ttsGetVoices()) | ||
ttsSetVoiceByIndex(1) | ttsSetVoiceByIndex(1) | ||
− | |||
</syntaxhighlight> | </syntaxhighlight> | ||
− | |||
==ttsSetVoiceByName== | ==ttsSetVoiceByName== | ||
;ttsSetVoiceByName(name) | ;ttsSetVoiceByName(name) | ||
− | : If you have multiple voices available, and know their name already, you can switch them with this function. | + | : If you have multiple voices available, and know their name already, you can switch them with this function. On macOS and Windows, adjusting the system voice adjusts this value automatically. |
: Returns true, if the setting was successful, false otherwise. | : Returns true, if the setting was successful, false otherwise. | ||
Line 349: | Line 411: | ||
: Text. The voice with this exact name will be set. | : Text. The voice with this exact name will be set. | ||
− | {{ | + | {{MudletVersion|3.17}} |
;Example | ;Example | ||
Line 357: | Line 419: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | ==ttsSkip== | |
− | == | + | ;ttsSkip() |
− | ; | ||
: Skips the current line of text. | : Skips the current line of text. | ||
See also: | See also: | ||
− | [[# | + | [[#ttsPause|ttsPause]], |
− | [[# | + | [[#ttsQueue|ttsQueue]] |
− | {{ | + | {{MudletVersion|3.17}} |
;Example | ;Example | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
− | + | ttsQueue("We hold these truths to be self-evident") | |
− | + | ttsQueue("that all species are created different but equal") | |
− | + | ttsQueue("that they are endowed with certain unalienable rights") | |
− | tempTimer(2, function () | + | tempTimer(2, function () ttsSkip() end) |
</syntaxhighlight> | </syntaxhighlight> |
Latest revision as of 09:10, 9 July 2022
Text to Speech Functions
These functions can make Mudlet talk for you (audible sound from written words). Check out the Text-To-Speech Manual for more detail on how this all works together.
Available in Mudlet3.17+
Several Mudlet events are available functionality as well:
- ttsSpeechStarted
- ttsSpeechReady
- ttsSpeechQueued
- ttsSpeechPaused
- ttsSpeechError
- ttsPitchChanged
- ttsRateChanged
- ttsVoiceChanged
- ttsVolumeChanged
ttsClearQueue
- ttsClearQueue([index])
- This function will help, if you have already queued a few lines of text to speak, and now want to remove some or all of them.
- Returns false if an invalid index is given.
- See also: ttsGetQueue, ttsQueue
- Parameters
- index:
- (optional) number. The text at this index position of the queue will be removed. If no number is given, the whole queue is cleared.
Available in Mudlet3.17+
- Example
-- queue five words and then remove some, "one, two, four" will be actually said
ttsQueue("One")
ttsQueue("Two")
ttsQueue("Three")
ttsQueue("Four")
ttsQueue("Five")
ttsClearQueue(2)
ttsClearQueue(3)
-- clear the whole queue entirely
ttsClearQueue()
ttsGetCurrentLine
- ttsGetCurrentLine()
- If you want to analyse if or what is currently said, this function is for you.
- Returns the text being spoken, or false if not speaking.
Available in Mudlet3.17+
- Example
ttsQueue("One")
ttsQueue("Two")
ttsQueue("Three")
ttsQueue("Four")
ttsQueue("Five")
-- print the line currently spoken 1s and 3s after which will be "two" and "five"
tempTimer(1, function()
echo("Speaking: ".. ttsGetCurrentLine().."\n")
end)
tempTimer(3, function()
echo("Speaking: ".. ttsGetCurrentLine().."\n")
end)
ttsGetCurrentVoice
- ttsGetCurrentVoice()
- If you have multiple voices available on your system, you may want to check which one is currently in use.
- Returns the name of the voice used for speaking.
See also: ttsGetVoices
Available in Mudlet3.17+
- Example
-- for example returns "Microsoft Zira Desktop" on Windows (US locale)
display(ttsGetCurrentVoice())
ttsGetPitch
- ttsGetPitch()
- If you want to analyse the pitch or tone of your current speech.
- Returns the current pitch as a number between 1 (high) and -1 (deep).
See also: ttsSetPitch
Available in Mudlet3.17+
- Example
local pitch = ttsGetPitch()
echo(pitch)
ttsGetQueue
- ttsGetQueue([index])
- This function can be used to show your current queue of texts, or any single text thereof.
- Returns a single text or a table of texts, or false. See index parameter for details.
See also: ttsQueue
- Parameters
- index
- (optional) number. The text at this index position of the queue will be returned. If no index is given, the whole queue will be returned. If the given index does not exist, the function returns false.
Available in Mudlet3.17+
- Example
ttsQueue("We begin with some text")
ttsQueue("And we continue it without interruption")
display(ttsGetQueue())
-- will show the queued texts as follows
-- (first line ignored because it's being spoken and is not in queue):
-- {
-- "And we continue it without interruption"
-- }
ttsGetRate
- ttsGetRate()
- If you want to analyse the rate or speed of your current speech.
- Returns the current rate as a number between 1 (fast) and -1 (slow).
See also: ttsSetRate
Available in Mudlet3.17+
- Example
local rate = ttsGetRate()
echo(rate)
ttsGetState
- ttsGetState()
- With this function you can find the current state of the speech engine.
- Returns one of: ttsSpeechReady, ttsSpeechPaused, ttsSpeechStarted, ttsSpeechError, ttsUnknownState.
See also: ttsSpeak, ttsPause, ttsResume, ttsQueue
Available in Mudlet3.17+
- Example
ttsQueue("We begin with some text")
ttsQueue("And we continue it without interruption")
echo(ttsGetState())
-- ttsSpeechStarted
ttsGetVoices
- ttsGetVoices()
- Lists all voices available to your current operating system and language settings. Currently uses the default system locale.
- Returns a table of names.
See also: ttsGetCurrentVoice, ttsSetVoiceByName, ttsSetVoiceByIndex
Available in Mudlet3.17+
- Example
display(ttsGetVoices())
-- for example returns the following on Windows (US locale)
-- {
-- "Microsoft Zira Desktop"
-- }
ttsGetVolume
- ttsGetVolume()
- If you want to analyse the volume of your current speech.
- Returns the current volume as a number between 1 (loud) and 0 (quiet).
See also: ttsSetVolume
Available in Mudlet3.17+
- Example
local volume = ttsGetVolume()
echo(volume)
ttsPause
- ttsPause()
- Pauses the speech which is currently spoken, if any. Engines on different OS's (Windows/macOS/Linux) behave differently - pause may not work at all, it may take several seconds before it takes effect, or it may pause instantly. Some engines will look for a break that they can later resume from, such as a sentence end.
Available in Mudlet3.17+
- Example
-- set some text to be spoken, pause it 2s later, and unpause 4s later
ttsSpeak("Sir David Frederick Attenborough is an English broadcaster and naturalist. He is best known for writing and presenting, in conjunction with the BBC Natural History Unit, the nine natural history documentary series that form the Life collection, which form a comprehensive survey of animal and plant life on Earth. Source: Wikipedia")
tempTimer(2, function() ttsPause() end)
tempTimer(2, function() ttsResume() end)
ttsQueue
- ttsQueue(text to queue, [index])
- This function will add the given text to your speech queue. Text from the queue will be spoken one after the other. This is opposed to ttsSpeak which will interrupt any spoken text immediately. The queue can be reviewed and modified, while their content has not been spoken.
See also: ttsGetQueue, ttsPause, ttsResume, ttsClearQueue, ttsGetState, ttsSpeak
- Parameters
- text to queue:
- Any written text which you would like to hear spoken to you. You can write literal text, or put in string variables, maybe taken from triggers or aliases, etc.
- index
- (optional) number. The text will be inserted to the queue at this index position. If no index is provided, the text will be added to the end of the queue.
Available in Mudlet3.17+
- Example
ttsQueue("We begin with some text")
ttsQueue("And we continue it without interruption")
display(ttsGetQueue())
-- will show the queued texts as follows
-- (first line ignored because it's being spoken and is not in queue):
-- {
-- "And we continue it without interruption"
-- }
ttsResume
- ttsResume()
- Resumes the speech which was previously spoken, if any has been paused.
Available in Mudlet3.17+
- Example
-- set some text to be spoken, pause it 2s later, and unpause 4s later
ttsSpeak("Sir David Frederick Attenborough is an English broadcaster and naturalist. He is best known for writing and presenting, in conjunction with the BBC Natural History Unit, the nine natural history documentary series that form the Life collection, which form a comprehensive survey of animal and plant life on Earth. Source: Wikipedia")
tempTimer(2, function() ttsPause() end)
tempTimer(4, function() ttsResume() end)
ttsSpeak
- ttsSpeak(text to speak)
- This will speak the given text immediately with the currently selected voice. Any currently spoken text will be interrupted (use the speech queue to queue a voice instead).
See also: ttsQueue
- Parameters
- text to speak:
- Any written text which you would like to hear spoken to you. You can write literal text, or put in string variables, maybe taken from triggers or aliases, etc.
Available in Mudlet3.17+
- Example
ttsSpeak("Hello World!")
-- if 'target' is your target variable, you can also do this:
ttsSpeak("Hello "..target)
ttsSetPitch
- ttsSetPitch(pitch)
- Sets the pitch or tone of speech playback.
- Parameters
- pitch:
- Number. Should be between 1 and -1, will be limited otherwise.
Available in Mudlet3.17+
- Example
-- talk deeply first, after 2 seconds talk highly, after 4 seconds normally again
ttsSetPitch(-1)
ttsQueue("Deep voice")
tempTimer(2, function()
ttsSetPitch(1)
ttsQueue("High voice")
end)
tempTimer(4, function()
ttsSetPitch(0)
ttsQueue("Normal voice")
end)
ttsSetRate
- ttsSetRate(rate)
- Sets the rate or speed of speech playback. On macOS and Windows, adjusting the system rate adjusts this value automatically.
- Parameters
- rate:
- Number. Should be between 1 and -1, will be limited otherwise.
Available in Mudlet3.17+
- Example
-- talk slowly first, after 2 seconds talk quickly, after 4 seconds normally again
ttsSetRate(-1)
ttsQueue("Slow voice")
tempTimer(2, function ()
ttsSetRate(1)
ttsQueue("Quick voice")
end)
tempTimer(4, function ()
ttsSetRate(0)
ttsQueue("Normal voice")
end)
ttsSetVolume
- ttsSetVolume(volume)
- Sets the volume of speech playback. On macOS, adjusting the system rate adjusts this value automatically.
- Parameters
- volume:
- Number. Should be between 1 and 0, will be limited otherwise.
Available in Mudlet3.17+
- Example
-- talk quietly first, after 2 seconds talk a bit louder, after 4 seconds normally again
ttsSetVolume(0.2)
ttsSpeak("Quiet voice")
tempTimer(2, function ()
ttsSetVolume(0.5)
ttsSpeak("Low voice")
end)
tempTimer(4, function ()
ttsSetVolume(1)
ttsSpeak("Normal voice")
end)
ttsSetVoiceByIndex
- ttsSetVoiceByIndex(index)
- If you have multiple voices available, you can switch them with this function by giving their index position as seen in the table you receive from ttsGetVoices(). If you know their name, you can also use ttsSetVoiceByName. On macOS and Windows, adjusting the system voice adjusts this value automatically.
- Returns true, if the setting was successful, errors otherwise.
See also: ttsGetVoices
- Parameters
- index:
- Number. The voice from this index position of the ttsGetVoices table will be set.
Available in Mudlet3.17+
- Example
display(ttsGetVoices())
ttsSetVoiceByIndex(1)
ttsSetVoiceByName
- ttsSetVoiceByName(name)
- If you have multiple voices available, and know their name already, you can switch them with this function. On macOS and Windows, adjusting the system voice adjusts this value automatically.
- Returns true, if the setting was successful, false otherwise.
See also: ttsGetVoices
- Parameters
- name:
- Text. The voice with this exact name will be set.
Available in Mudlet3.17+
- Example
display(ttsGetVoices())
ttsSetVoiceByName("Microsoft Zira Desktop") -- example voice on Windows
ttsSkip
- ttsSkip()
- Skips the current line of text.
Available in Mudlet3.17+
- Example
ttsQueue("We hold these truths to be self-evident")
ttsQueue("that all species are created different but equal")
ttsQueue("that they are endowed with certain unalienable rights")
tempTimer(2, function () ttsSkip() end)