Difference between revisions of "Manual:Text to Speech Functions"

From Mudlet
Jump to navigation Jump to search
m (→‎ttsSetVoiceByIndex: remove missing explanation)
(Remove 'speech' from functions)
Line 18: Line 18:
  
 
See also:  
 
See also:  
[[#ttsGetSpeechQueue|ttsGetSpeechQueue]], [[#ttsQueueSpeech|ttsQueueSpeech]]
+
[[#ttsGetQueue|ttsGetQueue]], [[#ttsQueue|ttsQueue]]
  
 
;Parameters
 
;Parameters
Line 29: Line 29:
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
 
-- queue five words and then remove "two" and "three" from the queue
 
-- queue five words and then remove "two" and "three" from the queue
ttsQueueSpeech("One")
+
ttsQueue("One")
ttsQueueSpeech("Two")
+
ttsQueue("Two")
ttsQueueSpeech("Three")
+
ttsQueue("Three")
ttsQueueSpeech("Four")
+
ttsQueue("Four")
ttsQueueSpeech("Five")
+
ttsQueue("Five")
 
ttsClearQueue(2)
 
ttsClearQueue(2)
 
ttsClearQueue(3)
 
ttsClearQueue(3)
Line 48: Line 48:
 
See also:  
 
See also:  
 
[[#ttsSpeak|ttsSpeak]],  
 
[[#ttsSpeak|ttsSpeak]],  
[[#ttsQueueSpeech|ttsQueueSpeech]]
+
[[#ttsQueue|ttsQueue]]
  
 
{{note}} Available since Mudlet 3.13
 
{{note}} Available since Mudlet 3.13
Line 75: Line 75:
  
  
==ttsGetSpeechQueue==
+
==ttsGetQueue==
;ttsGetSpeechQueue([index])
+
;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:  
[[#ttsQueueSpeech|ttsQueueSpeech]]
+
[[#ttsQueue|ttsQueue]]
  
 
;Parameters
 
;Parameters
Line 91: Line 91:
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
ttsQueueSpeech("We begin with some text")
+
ttsQueue("We begin with some text")
ttsQueueSpeech("And we continue it without interruption")
+
ttsQueue("And we continue it without interruption")
display(ttsGetSpeechQueue())
+
display(ttsGetQueue())
 
-- will show the queued texts as follows:
 
-- will show the queued texts as follows:
 
-- {
 
-- {
Line 102: Line 102:
  
 
==ttsGetState==
 
==ttsGetState==
;ttsGetSpeechState()
+
;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 108:
 
See also:  
 
See also:  
 
[[#ttsSpeak|ttsSpeak]],  
 
[[#ttsSpeak|ttsSpeak]],  
[[#ttsPauseSpeech|ttsPauseSpeech]],  
+
[[#ttsPause|ttsPause]],  
[[#ttsResumeSpeech|ttsResumeSpeech]],  
+
[[#ttsResume|ttsResume]],  
[[#ttsQueueSpeech|ttsQueueSpeech]]
+
[[#ttsQueue|ttsQueue]]
  
 
{{note}} Available since Mudlet 3.13
 
{{note}} Available since Mudlet 3.13
Line 143: Line 143:
  
  
==ttsPauseSpeech==
+
==ttsPause==
;ttsPauseSpeech()
+
;ttsPause()
 
: Pauses the speech which is currently spoken, if any.
 
: Pauses the speech which is currently spoken, if any.
  
 
See also:  
 
See also:  
[[#ttsResumeSpeech|ttsResumeSpeech]],  
+
[[#ttsResume|ttsResume]],  
[[#ttsQueueSpeech|ttsQueueSpeech]]
+
[[#ttsQueue|ttsQueue]]
  
 
{{note}} Available since Mudlet 3.13
 
{{note}} Available since Mudlet 3.13
Line 156: Line 156:
 
-- 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() ttsPauseSpeech() end)
+
tempTimer(2, function() ttsPause() end)
  
tempTimer(2, function() ttsResumeSpeech() end)
+
tempTimer(2, function() ttsResume() end)
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==ttsQueueSpeech==
+
==ttsQueue==
;ttsQueueSpeech(text to queue, [index])
+
;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:  
[[#ttsGetSpeechQueue|ttsGetSpeechQueue]],  
+
[[#ttsGetQueue|ttsGetQueue]],  
[[#ttsPauseSpeech|ttsPauseSpeech]],  
+
[[#ttsPause|ttsPause]],  
[[#ttsResumeSpeech|ttsResumeSpeech]],  
+
[[#ttsResume|ttsResume]],  
 
[[#ttsClearQueue|ttsClearQueue]],  
 
[[#ttsClearQueue|ttsClearQueue]],  
 
[[#ttsGetState|ttsGetState]],  
 
[[#ttsGetState|ttsGetState]],  
Line 183: Line 183:
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
ttsQueueSpeech("We begin with some text")
+
ttsQueue("We begin with some text")
ttsQueueSpeech("And we continue it without interruption", 1)
+
ttsQueue("And we continue it without interruption", 1)
display(ttsGetSpeechQueue())
+
display(ttsGetQueue())
 
-- The texts have changed order, the second will be spoken first.  
 
-- The texts have changed order, the second will be spoken first.  
 
-- The queue shows as follows:
 
-- The queue shows as follows:
Line 194: Line 194:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==ttsResumeSpeech==
+
==ttsResume==
;ttsResumeSpeech()
+
;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:  
[[#ttsPauseSpeech|ttsPauseSpeech]],  
+
[[#ttsPause|ttsPause]],  
[[#ttsQueueSpeech|ttsQueueSpeech]]
+
[[#ttsQueue|ttsQueue]]
  
 
{{note}} Available since Mudlet 3.13
 
{{note}} Available since Mudlet 3.13
Line 207: Line 207:
 
-- 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() ttsPauseSpeech() end)
+
tempTimer(2, function() ttsPause() end)
  
tempTimer(2, function() ttsResumeSpeech() end)
+
tempTimer(2, function() ttsResume() end)
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Line 217: Line 217:
  
 
See also:  
 
See also:  
[[#ttsQueueSpeech|ttsQueueSpeech]]
+
[[#ttsQueue|ttsQueue]]
  
 
;Parameters
 
;Parameters
Line 233: Line 233:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==ttsSetSpeechPitch==
+
==ttsSetPitch==
;ttsSetSpeechPitch(pitch)
+
;ttsSetPitch(pitch)
 
: Sets the pitch of speech playback.
 
: Sets the pitch of speech playback.
  
Line 246: Line 246:
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
 
-- talk deeply first, after 2 seconds talk highly, after 4 seconds normally again
 
-- talk deeply first, after 2 seconds talk highly, after 4 seconds normally again
ttsSetSpeechPitch(-1)
+
ttsSetPitch(-1)
ttsQueueSpeech("Deep voice")
+
ttsQueue("Deep voice")
  
 
tempTimer(2, function()
 
tempTimer(2, function()
   ttsSetSpeechPitch(1)
+
   ttsSetPitch(1)
   ttsQueueSpeech("High voice")
+
   ttsQueue("High voice")
 
end)
 
end)
  
 
tempTimer(4, function()
 
tempTimer(4, function()
   ttsSetSpeechPitch(0)
+
   ttsSetPitch(0)
   ttsQueueSpeech("Normal voice")
+
   ttsQueue("Normal voice")
 
end)
 
end)
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==ttsSetSpeechRate==
+
==ttsSetRate==
;ttsSetSpeechRate(rate)
+
;ttsSetRate(rate)
 
: Sets the rate of speech playback.
 
: Sets the rate of speech playback.
  
Line 273: Line 273:
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
 
-- talk slowly first, after 2 seconds talk quickly, after 4 seconds normally again
 
-- talk slowly first, after 2 seconds talk quickly, after 4 seconds normally again
ttsSetSpeechRate(-1)
+
ttsSetRate(-1)
ttsQueueSpeech("Slow voice")
+
ttsQueue("Slow voice")
  
 
tempTimer(2, function ()
 
tempTimer(2, function ()
   ttsSetSpeechRate(1)
+
   ttsSetRate(1)
   ttsQueueSpeech("Quick voice")
+
   ttsQueue("Quick voice")
 
end)
 
end)
  
 
tempTimer(4, function ()
 
tempTimer(4, function ()
   ttsSetSpeechRate(0)
+
   ttsSetRate(0)
  ttsQueueSpeech("Normal voice")
+
  ttsQueue("Normal voice")
 
end)
 
end)
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==ttsSetSpeechVolume==
+
==ttsSetVolume==
;ttsSetSpeechVolume(volume)
+
;ttsSetVolume(volume)
 
: Sets the volume of speech playback.
 
: Sets the volume of speech playback.
  
Line 300: Line 300:
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
 
-- talk quietly first, after 2 seconds talk a bit louder, after 4 seconds normally again
 
-- talk quietly first, after 2 seconds talk a bit louder, after 4 seconds normally again
ttsSetSpeechVolume(0.2)
+
ttsSetVolume(0.2)
 
ttsSpeak("Quiet voice")
 
ttsSpeak("Quiet voice")
  
 
tempTimer(2, function ()
 
tempTimer(2, function ()
   ttsSetSpeechVolume(0.5)
+
   ttsSetVolume(0.5)
 
   ttsSpeak("Low voice")
 
   ttsSpeak("Low voice")
 
end)
 
end)
  
 
tempTimer(4, function ()  
 
tempTimer(4, function ()  
   ttsSetSpeechVolume(1)
+
   ttsSetVolume(1)
 
   ttsSpeak("Normal voice")
 
   ttsSpeak("Normal voice")
 
end)
 
end)
Line 355: Line 355:
  
  
==ttsSkipSpeech==
+
==ttsSkip==
;ttsSkipSpeech()
+
;ttsSkip()
 
: Skips the current line of text.
 
: Skips the current line of text.
  
 
See also:  
 
See also:  
[[#ttsPauseSpeech|ttsPauseSpeech]],  
+
[[#ttsPause|ttsPause]],  
[[#ttsQueueSpeech|ttsQueueSpeech]]
+
[[#ttsQueue|ttsQueue]]
  
 
{{note}} Available since Mudlet 3.13
 
{{note}} Available since Mudlet 3.13
Line 367: Line 367:
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
ttsQueueSpeech("We hold these truths to be self-evident")
+
ttsQueue("We hold these truths to be self-evident")
ttsQueueSpeech("that all species are created different but equal")
+
ttsQueue("that all species are created different but equal")
ttsQueueSpeech("that they are endowed with certain unalienable rights")
+
ttsQueue("that they are endowed with certain unalienable rights")
tempTimer(2, function () ttsSkipSpeech() end)
+
tempTimer(2, function () ttsSkip() end)
 
</syntaxhighlight>
 
</syntaxhighlight>

Revision as of 04:27, 19 August 2018

Text to Speech Functions

These functions can make Mudlet talk for you (audible sound from written words). The feature is available since Mudlet version 3.13. Check out the Text-To-Speech Manual for more detail on how this all works together.

Several Mudlet events are available functionality as well:

  • ttsSpeechStarted
  • ttsSpeechReady
  • ttsSpeechQueued
  • ttsSpeechPaused
  • ttsSpeechError


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.

Note Note: Available since Mudlet 3.13

Example
-- queue five words and then remove "two" and "three" from the queue
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.

See also: ttsSpeak, ttsQueue

Note Note: Available since Mudlet 3.13


-- print the line currently spoken
echo(ttsGetCurrentLine())

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

Note Note: Available since Mudlet 3.13

Example
-- for example returns "Microsoft Zira Desktop" on Windows (US locale)
ttsGetCurrentVoice()


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.

Note Note: Available since Mudlet 3.13

Example
ttsQueue("We begin with some text")
ttsQueue("And we continue it without interruption")
display(ttsGetQueue())
-- will show the queued texts as follows:
-- {
--   "We begin with some text",
--   "And we continue it without interruption"
-- }

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

Note Note: Available since Mudlet 3.13

Example
ttsSpeak("This is just a test!")
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

Note Note: Available since Mudlet 3.13

Example
display(ttsGetVoices())
-- for example returns the following on Windows (US locale)
-- {
--   "Microsoft Zira Desktop"
-- }


ttsPause

ttsPause()
Pauses the speech which is currently spoken, if any.

See also: ttsResume, ttsQueue

Note Note: Available since Mudlet 3.13

-- 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.

Note Note: Available since Mudlet 3.13

Example
ttsQueue("We begin with some text")
ttsQueue("And we continue it without interruption", 1)
display(ttsGetQueue())
-- The texts have changed order, the second will be spoken first. 
-- The queue shows as follows:
-- {
--  "We begin with some text",
--  "And we continue it without interruption"
-- }

ttsResume

ttsResume()
Resumes the speech which was previously spoken, if any has been paused.

See also: ttsPause, ttsQueue

Note Note: Available since Mudlet 3.13

-- 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)

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.

Note Note: Available since Mudlet 3.13

Example
ttsSpeak("Hello World!")

-- if 'target' is your target variable, you can also do this:
ttsSpeak("Hello "..target)

ttsSetPitch

ttsSetPitch(pitch)
Sets the pitch of speech playback.
Parameters
  • pitch:
Number. Should be between 1 and -1, will be limited otherwise.

Note Note: Available since Mudlet 3.13

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 of speech playback.
Parameters
  • rate:
Number. Should be between 1 and -1, will be limited otherwise.

Note Note: Available since Mudlet 3.13

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.
Parameters
  • volume:
Number. Should be between 1 and 0, will be limited otherwise.

Note Note: Available since Mudlet 3.13

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.
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.

Note Note: Available since Mudlet 3.13

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.
Returns true, if the setting was successful, false otherwise.

See also: ttsGetVoices

Parameters
  • name:
Text. The voice with this exact name will be set.

Note Note: Available since Mudlet 3.13

Example
display(ttsGetVoices())
ttsSetVoiceByName("Microsoft Zira Desktop") -- example voice on Windows


ttsSkip

ttsSkip()
Skips the current line of text.

See also: ttsPause, ttsQueue

Note Note: Available since Mudlet 3.13

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)