|
VoiceResourcePlay Method (Byte) |
Plays the specified byte array of audio using the current
Audio Codec of the Voice Resource.
Namespace:
VoiceElements.Client
Assembly:
VoiceElementsClient (in VoiceElementsClient.dll) Version: 8.6.1.1
Syntax public TerminationCode Play(
byte[] buffer
)
Public Function Play (
buffer As Byte()
) As TerminationCode
public:
TerminationCode Play(
array<unsigned char>^ buffer
)
member Play :
buffer : byte[] -> TerminationCode
Parameters
- buffer
- Type: SystemByte
The buffer or byte array containing the data to play.
Return Value
Type:
TerminationCode
A
Termination Code indicating how the play ended. Typically, you will use this to determine what to do next.
Remarks Typical Use Over Play a File
Most developers will opt to use the
Direct File Play Method to play audio. As you can see in the code sample below, you can easily take a file and turn it into
a
File Stream and put that into an array of bytes and execute the play. However, most often this method is used by those who desire to store their audio in a database as a
BLOB Data Type and stream it right from there.
General Concepts: Audio in Voice Elements and Telephony
Voice Elements supports a wide range of audio file types and formats, for a detailed list of these formats, see
Supported Audio Codecs. Most of these formats that we recommend
are
Wave Files. You may need to convert your audio into one of these formats, depending on the source.
- Telephony Sound Processing: Audio Quality
Before discussing converting your audio files, we need to point out that all audio transmitted over a telephony carrier is typically converted down to 8khz 8bit Mulaw (aka G711) quality in transmission (some countries use ALaw, and in addition to G711, G729 is also another codec that can be used). Therefore, higher quality files will not result in
a better sounding connection. We also recommend converting your files to this codec to save conversion before tranmission every time. To play files of a different type, you may change the Voice Resource Codec Property
to any of the supported codecs.
- Converting Your Audio Files
There are several applications available that you can easily use to convert to 8khz 8bit Mulaw format from almost any other format. We have had good results with GoldWave, WavePad
and Open Source Audacity. If you need to convert your files in real time (i.e. during a call), we recommend Open Source SOX.
- FAQ: Audio Doesn't Sound Clear?
This is usually a codec mismatch. Either convert your files or change the Voice Resource Codec Property to the one in which your files were encoded.
- FAQ: Can I Use MP3 Files?
Voice Elements does not support MP3 files, which are usually in a far higher quality than needed for telephony. See above on ways to convert your files to 8khz 8bit Mulaw.
Examples
The following sample code sets up a
Channel Resource,
Dials a Call, retrieves a
Voice Resource,
sets the
Audio Codec. It then takes an audio file, creates a
File Stream and uses that to populate a byte array and plays it.
public void DialOutAndPlayByteArray()
{
TelephonyServer m_TelephonyServer = new TelephonyServer();
ChannelResource m_ChannelResource = m_TelephonyServer.GetChannel();
string phoneNumber = "2135551212";
m_ChannelResource.Dial(phoneNumber);
VoiceResource m_VoiceResource = m_ChannelResource.VoiceResource;
m_VoiceResource.Codec = Codec.MULAW_8Khz_8Bit;
FileStream fs = new FileStream(@"C:\Audio\HelloCaller.wav", FileMode.Open);
byte[] byteArray = new byte[fs.Length];
fs.Read(byteArray, 0, (int)fs.Length);
fs.Close();
m_VoiceResource.Play(byteArray);
}
Public Sub DialOutAndPlayByteArray()
Dim m_TelephonyServer As New TelephonyServer()
Dim m_ChannelResource As ChannelResource = m_TelephonyServer.GetChannel()
Dim phoneNumber As String = "2135551212"
m_ChannelResource.Dial(phoneNumber)
Dim m_VoiceResource As VoiceResource = m_ChannelResource.VoiceResource
m_VoiceResource.Codec = Codec.MULAW_8Khz_8Bit
Dim fs As New FileStream("C:\Audio\HelloCaller.wav", FileMode.Open)
Dim byteArray As Byte() = New Byte(fs.Length - 1) {}
fs.Read(byteArray, 0, CInt(fs.Length))
fs.Close()
m_VoiceResource.Play(byteArray)
End Sub
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
See Also