Send data buffer of sound data to stream.
Function
- int StreamSendData(void* SoundData, int SoundDataLength)
Parameters
SoundData
Pointer to the memory buffer containing the sound data.
SoundDataLength
Size of the sound data, in bytes.
Return Values
LV_SUCCESS
No errors; data accepted.
LV_STREAM_NOT_ACCEPTED
The data was not accepted, likely because the port was not ready to receive data. Ensure that StreamStart was called first.
LV_INVALID_HPORT
The port is not valid (either CreateClient has not been called or DestroyClient has been called prior to this call).
LV_FAILURE
The operation failed because the port was shutting down.
LV_EXCEPTION
An exception occurred while processing the request.
Example
This function is used to do the actual streaming. Call it with each filled sound data buffer, in a function similar to the one below. This call copies sound data to an internal buffer and returns immediately. The processing of sound data takes place on a background thread.
C++ Code
void StreamAudio(LVSpeechPort port)
{
char* current_pos;
int single_chunk = 160;
int audio_processed = 0;
current pos = audio_buffer;
port.StreamStart();
while(current_pos < audio_buffer + audio_size)
{
- // If the next iteration would bring the audio stream past
- // the end of the buffer, set the amount to be streamed
- // equal to the remaining space in the buffer.
- if((audio_processed + single_chunk) > audio_size)
single_chunk = audio_size - audio_processed;
- // Send data to the voicechannel and increment the current position.
- port.StreamSendData(current_pos, single_chunk);
- current_pos += single_chunk;
- audio_processed += single_chunk;
- Sleep((DWORD)(single_chunk / 8))
}
}
See Also