-
Notifications
You must be signed in to change notification settings - Fork 2
Getting Started \ Recording Audio
SirusDoma edited this page Sep 15, 2018
·
4 revisions
In addition to playback, you can also record audio from audio input device. You can either left the audio device to default or pick them manually.
To initiate audio capture, use following codes:
// Capture audio with 44100 as the sample rate
SoundRecorder<Sound> recorder = SoundSystem.Instance.Capture(44100);By default, the sample rate is 44100 and the recorded data will be stored into Sound object, you don't have to specify the sample rate if you aren't sure what sample rate to use.
Once recording session is started, you can stop it by calling Stop() method.
// Stop recording the data
recorder.Stop();
// Retrieve the output of recording, by default it's sound object
Sound recordedSound = recorder.Output;Here a proper example to use SoundRecorder:
using (var recorder = SoundSystem.instance.Capture())
{
// Now we will capture sound that worth for 10 seconds
var stopwatch = new Stopwatch();
stopwatch.Start();
// Now we need keep updating the sound system, this will also update the SoundRecorder while it's capturing
while (stopwatch.ElapsedMilliseconds < 10000f)
{
// It is good opportunity to update the sound system
SoundSystem.Instance.Update(0);
}
// Stop the recording session
SoundSystem.Instance.Stop(recorder);
stopwatch.Stop();
// Save the output to the file
recorder.Output.Save("recording.wav");
}Copyright © 2018 - SirusDoma
This is an open-sourced library licensed under the MIT License.