PvSpeaker
.NET API
API Reference for the PvSpeaker .NET SDK (NuGet)
namespace: Pv
PvSpeaker
Class for PvSpeaker.
PvSpeaker.PvSpeaker()
PvSpeaker
constructor.
Parameters
sampleRate
int : The sample rate of the audio to be played.bitsPerSample
int : The number of bits per sample of the audio to be played.deviceIndex
int : The index of the audio device to play audio from. A value of (-1) will use the default audio device.bufferSizeSecs
int : The size in seconds of the internal buffer used to buffer PCM data - i.e. internal circular buffer will be of sizesampleRate
*bufferSizeSecs
.
Returns
PvSpeaker
: An instance of PvSpeaker.
Throws
PvSpeakerException
: If an error occurs while creating an instance of PvSpeaker.
PvSpeaker.Dispose()
Frees memory used by the PvSpeaker
instance.
PvSpeaker.GetAvailableDevices()
Gets a list of the available audio output devices on the current system.
Returns
string[]
: An array of strings containing the names of the audio devices.
Throws
PvSpeakerException
: If an error occurs while getting audio device info.
PvSpeaker.Start()
Starts the audio output device. Should be called before making any calls to Write()
, Flush()
, or Stop()
.
Throws
PvSpeakerException
: If an error occurs while starting the audio device.
PvSpeaker.Stop()
Stops the audio output device. Should only be called after a successful call to Start()
.
Throws
PvSpeakerException
: If an error occurs while stopping the audio device.
PvSpeaker.Write()
Synchronous call to write PCM data to the internal circular buffer for audio playback. Only writes as much PCM data as the internal circular buffer can currently fit, and returns the number of samples that were successfully written. Call between Start()
and Stop()
.
Parameters
pcm
byte[] : PCM data to be played.
Returns
int
: Number of samples that were successfully written.
Throws
PvSpeakerException
: If an error occurs while writing audio data.
PvSpeaker.Flush()
Synchronous call to write PCM data to the internal circular buffer for audio playback. This call blocks the thread until all PCM data has been successfully written and played. Call between Start()
and Stop()
.
Parameters
pcm
byte[] : Optional PCM data to be played.
Returns
int
: Number of samples that were successfully written.
Throws
PvSpeakerException
: If an error occurs while flushing audio data.
PvSpeaker.WriteToFile()
Writes PCM data passed to PvSpeaker to a specified WAV file.
Throws
PvSpeakerException
: If an error occurs while writing to the output file.
PvSpeaker.IsStarted
Gets whether the speaker has started and is available to receive PCM data or not.
PvSpeaker.SampleRate
Gets the sample rate matching the value passed to the constructor.
PvSpeaker.BitsPerSample
Gets the bits per sample matching the value passed to the constructor.
PvSpeaker.BufferSizeSecs
Gets the buffer size in seconds matching the value passed to the constructor.
PvSpeaker.SelectedDevice
Gets the current selected audio device.
PvSpeaker.Version
Gets the current version of the library.
PvSpeakerException
Exception thrown if an error occurs within PvSpeaker
.
Exceptions: