Libraries.Sound.Microphone Documentation

Inherits from: Libraries.Language.Object

Summary

Actions Summary Table

ActionsDescription
Compare(Libraries.Language.Object object)This action compares two object hash codes and returns an integer.
Equals(Libraries.Language.Object object)This action determines if two objects are equal based on their hash code values.
GetHashCode()This action gets the hash code for an object.
GetSamples()The GetSamples action returns the samples that have been recorded by the Microphone.
GetSize()The GetSize action returns the number of samples that can be stored in each AudioSamples object returned by GetSamples.
GetSizeInSeconds()The GetSizeInSeconds action returns how many seconds of audio can be stored in any AudioSamples objects returned by the GetSamples action.
IsRecording()The IsRecording action returns whether or not this Microphone is currently recording.
Record()The Record action makes the Microphone begin recording.
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.
SetSize(integer samples)The SetSize action sets the number of samples that can be stored in each AudioSamples object returned by GetSamples.
SetSizeInSeconds(number seconds)The SetSizeInSeconds action sets how many seconds of audio can be stored in any AudioSamples objects returned by the GetSamples action.
Stop()The Stop action stops Microphone recording.

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.

Example Code

Object o
        Object t
        integer result = o:Compare(t) //1 (larger), 0 (equal), or -1 (smaller)

Parameters

Return

integer: The Compare result, Smaller, Equal, or Larger.

Equals(Libraries.Language.Object object)

This action determines if two objects are equal based on their hash code values.

Example Code

use Libraries.Language.Object
        use Libraries.Language.Types.Text
        Object o
        Text t
        boolean result = o:Equals(t)

Parameters

Return

boolean: True if the hash codes are equal and false if they are not equal.

GetHashCode()

This action gets the hash code for an object.

Example Code

Object o
        integer hash = o:GetHashCode()

Return

integer: The integer hash code of the object.

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.

Example Code

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

Return

Libraries.Sound.AudioSamples: The recorded AudioSamples, or undefined if none are available.

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.

Example Code

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

Return

integer: The number of samples that can be stored in any AudioSamples returned by GetSamples.

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.

Example Code

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

Return

number: The number of seconds that can be stored in any AudioSamples returned by GetSamples.

IsRecording()

The IsRecording action returns whether or not this Microphone is currently recording.

Example Code

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

Return

boolean: Whether or not this Microphone is currently recording.

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 Code

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.

Example Code

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

Parameters

Return

Libraries.Sound.AudioSamples: An AudioSamples object containing the recorded sounds.

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.

Example Code

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

Parameters

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.

Example Code

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

Parameters

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 Code

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