Difference between revisions of "Lua:playSound"

From Cheat Engine
Jump to navigation Jump to search
(Creating Files)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
[[Category:Lua]]
 
[[Category:Lua]]
'''function''' playSound(''stream'', ''waittilldone'')
+
{{CodeBox|'''function''' playSound(''stream'', ''waittilldone'') ''':''' void}}
 +
{{CodeBox|'''function''' playSound(''tablefile'', ''waittilldone'') ''':''' void}}
  
'''function''' playSound(''tablefile'', ''waittilldone'')
+
Plays a .WAV formatted sound from either a memory stream or a table file.
  
Plays a sound file
+
When a memory stream is provided, it must contain a .WAV formatted memory object. When a table file is provided, the memory stream stored inside the table file will be used and played.
 +
 
 +
If ''waittilldone'' is true, the script will stop executing until the sound has finished playing.
 +
 
 +
Cheat Engine provides two predefined table files named "Activate" and "Deactivate". These can be used directly or overridden.
  
 
===Function Parameters===
 
===Function Parameters===
{|width="85%" cellpadding="10%" cellpadding="5%" cellspacing="0" border="0"
+
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
 
!align="left"|Parameter
 
!align="left"|Parameter
 
!align="left"|Type
 
!align="left"|Type
!style="width: 60%;background-color:white;" align="left"|Description
+
!style="width: 80%;background-color:white;" align="left"|Description
 
|-
 
|-
 
|stream
 
|stream
|[[Stream]]
+
|MemoryStream
|A Stream object, can be [[MemoryStream]] or [[FileStream]]
+
|A memory stream containing a .WAV formatted memory object.
 
|-
 
|-
 
|tablefile
 
|tablefile
|[[TableFile]]
+
|TableFile
|A [[TableFile]] object, a file added and stored in the cheat table
+
|A table file containing a memory stream that will be played as sound.
 
|-
 
|-
 
|waittilldone
 
|waittilldone
|Boolean
+
|Boolean (optional)
|If true, the next LUA instruction will not execute until the sound is done playing
+
|If true, the script waits until the sound has finished playing before continuing execution.
 
|}
 
|}
  
===Samples===
+
===Returns===
 +
void — This function does not return any value.
  
Calling from LUA
+
===Examples===
 +
<pre>
 +
playSound(findTableFile("Activate"))
  
<pre>playSound(findTableFile('protected.wav'))</pre>
+
-- Wait until the sound has finished playing
 
+
playSound(findTableFile("Deactivate"), true)
Calling from an AA Script:
 
 
 
<pre>[enable]
 
luacall(playSound(findTableFile('protected.wav')))
 
globals+1034:
 
  dd 1
 
 
 
[disable]
 
luacall(playSound(findTableFile('cleared.wav')))
 
globals+1034:
 
  dd 2
 
 
</pre>
 
</pre>
 
===Creating Files===
 
I am unsure of the formats supported, but using [http://audacityteam.org/ Audacity]
 
worked for me.  I recorded my microphone and selected just the portion I wanted, then
 
used "File->Export Selected Audio" to export it as 'WAV (Microsoft) signed 16-bit PCM'.
 
 
You can use a free online text-to-speech wav file generator at [http://www.text2speech.org/](http://www.text2speech.org/).
 
  
 
{{LuaSeeAlso}}
 
{{LuaSeeAlso}}
 
=== Related Functions ===
 
* [[Lua:findTableFile|findTableFile]]
 
 
=== Related Classes ===
 
* [[Lua:Class:Stream|Stream]]
 
* [[Lua:Class:FileStream|FileStream]]
 
* [[Lua:Class:MemoryStream|MemoryStream]]
 

Latest revision as of 03:58, 21 June 2026

<> Function

function playSound(stream, waittilldone) : void

<> Function

function playSound(tablefile, waittilldone) : void

Plays a .WAV formatted sound from either a memory stream or a table file.

When a memory stream is provided, it must contain a .WAV formatted memory object. When a table file is provided, the memory stream stored inside the table file will be used and played.

If waittilldone is true, the script will stop executing until the sound has finished playing.

Cheat Engine provides two predefined table files named "Activate" and "Deactivate". These can be used directly or overridden.

Function Parameters[edit]

Parameter Type Description
stream MemoryStream A memory stream containing a .WAV formatted memory object.
tablefile TableFile A table file containing a memory stream that will be played as sound.
waittilldone Boolean (optional) If true, the script waits until the sound has finished playing before continuing execution.

Returns[edit]

void — This function does not return any value.

Examples[edit]

playSound(findTableFile("Activate"))

-- Wait until the sound has finished playing
playSound(findTableFile("Deactivate"), true)

See also[edit]

Lua
Script Engine