Libraries.Sound.Microphone Documentation
Inherits from: Libraries.Language.Object
Actions Documentation
Compare(Libraries.Language.Object object)
This action compares two object hash codes and returns an integer. The result is larger if this hash code is larger than the object passed as a parameter, smaller, or equal. In this case, -1 means smaller, 0 means equal, and 1 means larger. This action was changed in Quorum 7 to return an integer, instead of a CompareResult object, because the previous implementation was causing efficiency issues.
Parameters
- Libraries.Language.Object: The object to compare to.
Return
integer: The Compare result, Smaller, Equal, or Larger.
Example
Object o
Object t
integer result = o:Compare(t) //1 (larger), 0 (equal), or -1 (smaller)
Equals(Libraries.Language.Object object)
This action determines if two objects are equal based on their hash code values.
Parameters
- Libraries.Language.Object: The to be compared.
Return
boolean: True if the hash codes are equal and false if they are not equal.
Example
use Libraries.Language.Object
use Libraries.Language.Types.Text
Object o
Text t
boolean result = o:Equals(t)
GetHashCode()
This action gets the hash code for an object.
Return
integer: The integer hash code of the object.
Example
Object o
integer hash = o:GetHashCode()
GetSamples()
The GetSamples action returns the samples that have been recorded by the Microphone. If no samples are currently available (either because the Microphone is not recording or because no more samples have been captured since the last time GetSamples was called) then this returns undefined. As such, all output from this action should be tested to ensure it is not undefined before use.
Return
Libraries.Sound.AudioSamples: The recorded AudioSamples, or undefined if none are available.
Example
use Libraries.Sound.AudioSamples
use Libraries.Sound.Microphone
use Libraries.Sound.Audio
use Libraries.System.DateTime
use Libraries.System.SystemHelper
DateTime time
Microphone microphone
Audio audio
SystemHelper helper
number startTime = time:GetEpochTime()
// We set the microphone to record up to 1 second of audio between requests for samples.
microphone:SetSizeInSeconds(1)
microphone:Record()
repeat while time:GetEpochTime() - startTime < 5000
AudioSamples samples = microphone:GetSamples()
if samples not= undefined
audio:AddToQueue(samples)
end
// Wait for 100 miliseconds before checking for more audio.
helper:Sleep(100)
end
microphone:Stop()
audio:Play()
repeat while audio:IsPlaying()
audio:Stream()
end
GetSize()
The GetSize action returns the number of samples that can be stored in each AudioSamples object returned by GetSamples. If recorded audio exceeds the size of the AudioSamples, the beginning of the recorded audio will be cut off. When recording, the Microphone records 44100 samples per second.
Return
integer: The number of samples that can be stored in any AudioSamples returned by GetSamples.
Example
use Libraries.Sound.Microphone
Microphone microphone
output "The microphone stores up to " + microphone:GetSize() + " samples of audio by default."
output "The microphone records up to " + microphone:GetSizeInSeconds() + " seconds of audio by default."
GetSizeInSeconds()
The GetSizeInSeconds action returns how many seconds of audio can be stored in any AudioSamples objects returned by the GetSamples action. If recorded audio exceeds the size of the AudioSamples, the beginning of the recorded audio will be cut off.
Return
number: The number of seconds that can be stored in any AudioSamples returned by GetSamples.
Example
use Libraries.Sound.Microphone
Microphone microphone
output "The microphone stores up to " + microphone:GetSize() + " samples of audio by default."
output "The microphone records up to " + microphone:GetSizeInSeconds() + " seconds of audio by default."
IsRecording()
The IsRecording action returns whether or not this Microphone is currently recording.
Return
boolean: Whether or not this Microphone is currently recording.
Example
use Libraries.Sound.Microphone
Microphone microphone
output "Microphone recording yet? " + microphone:IsRecording()
microphone:Record()
output "Is the Microphone recording now? " + microphone:IsRecording()
microphone:Stop()
output "Is the Microphone still recording? " + microphone:IsRecording()
Record()
The Record action makes the Microphone begin recording. This call is non-blocking, which means code will continue to execute after calling this action. While the Microphone is recording, AudioSamples may be fetched from the microphone using the GetSamples action.
Example
use Libraries.Sound.AudioSamples
use Libraries.Sound.Microphone
use Libraries.Sound.Audio
use Libraries.System.DateTime
use Libraries.System.SystemHelper
DateTime time
Microphone microphone
Audio audio
SystemHelper helper
number startTime = time:GetEpochTime()
// We set the microphone to record up to 1 second of audio between requests for samples.
microphone:SetSizeInSeconds(1)
microphone:Record()
repeat while time:GetEpochTime() - startTime < 5000
AudioSamples samples = microphone:GetSamples()
if samples not= undefined
audio:AddToQueue(samples)
end
// Wait for 100 miliseconds before checking for more audio.
helper:Sleep(100)
end
microphone:Stop()
audio:Play()
repeat while audio:IsPlaying()
audio:Stream()
end
RecordUntilDone(number seconds)
The RecordUntilDone action will wait for the given number of seconds and return an AudioSamples object containing the recorded audio data over that time. This call is blocking, which means program execution must wait until this call is finished before it moves to the next line of code in the program.
Parameters
- number seconds: How many seconds of audio to record.
Return
Libraries.Sound.AudioSamples: An AudioSamples object containing the recorded sounds.
Example
use Libraries.Sound.AudioSamples
use Libraries.Sound.Microphone
use Libraries.Sound.Audio
Microphone microphone
AudioSamples recording = microphone:RecordUntilDone(5)
Audio audio
audio:Load(recording)
audio:PlayUntilDone()
SetSize(integer samples)
The SetSize action sets the number of samples that can be stored in each AudioSamples object returned by GetSamples. If recorded audio exceeds the size of the AudioSamples, the beginning of the recorded audio will be cut off. When recording, the Microphone records 44100 samples per second.
Parameters
- integer samples: The maximum number of samples that should be stored in each AudioSamples object returned by GetSamples.
Example
use Libraries.Sound.AudioSamples
use Libraries.Sound.Microphone
use Libraries.Sound.Audio
use Libraries.System.DateTime
use Libraries.System.SystemHelper
DateTime time
Microphone microphone
Audio audio
SystemHelper helper
number startTime = time:GetEpochTime()
// We set the microphone to record up to 44100 samples of audio between requests for samples.
microphone:SetSize(44100)
microphone:Record()
repeat while time:GetEpochTime() - startTime < 5000
AudioSamples samples = microphone:GetSamples()
if samples not= undefined
audio:AddToQueue(samples)
end
// Wait for 100 miliseconds before checking for more audio.
helper:Sleep(100)
end
microphone:Stop()
audio:Play()
repeat while audio:IsPlaying()
audio:Stream()
end
SetSizeInSeconds(number seconds)
The SetSizeInSeconds action sets how many seconds of audio can be stored in any AudioSamples objects returned by the GetSamples action. If recorded audio exceeds the size of the AudioSamples, the beginning of the recorded audio will be cut off.
Parameters
- number seconds: The maximum number of seconds that should be stored in each AudioSamples object returned by GetSamples.
Example
use Libraries.Sound.AudioSamples
use Libraries.Sound.Microphone
use Libraries.Sound.Audio
use Libraries.System.DateTime
use Libraries.System.SystemHelper
DateTime time
Microphone microphone
Audio audio
SystemHelper helper
number startTime = time:GetEpochTime()
// We set the microphone to record up to 1 second of audio between requests for samples.
microphone:SetSizeInSeconds(1)
microphone:Record()
repeat while time:GetEpochTime() - startTime < 5000
AudioSamples samples = microphone:GetSamples()
if samples not= undefined
audio:AddToQueue(samples)
end
// Wait for 100 miliseconds before checking for more audio.
helper:Sleep(100)
end
microphone:Stop()
audio:Play()
repeat while audio:IsPlaying()
audio:Stream()
end
Stop()
The Stop action stops Microphone recording. Once stopped, the Microphone will not collect any more AudioSamples, but the last samples that were recorded can still be retrieved from GetSamples.
Example
use Libraries.Sound.AudioSamples
use Libraries.Sound.Microphone
use Libraries.Sound.Audio
use Libraries.System.DateTime
use Libraries.System.SystemHelper
DateTime time
Microphone microphone
Audio audio
SystemHelper helper
number startTime = time:GetEpochTime()
// We set the microphone to record up to 1 second of audio between requests for samples.
microphone:SetSizeInSeconds(1)
microphone:Record()
repeat while time:GetEpochTime() - startTime < 5000
AudioSamples samples = microphone:GetSamples()
if samples not= undefined
audio:AddToQueue(samples)
end
// Wait for 100 miliseconds before checking for more audio.
helper:Sleep(100)
end
microphone:Stop()
audio:Play()
repeat while audio:IsPlaying()
audio:Stream()
end