Browse
 
Tools
Rss Categories

LVSpeechPort::StreamSendData

Reference Number: AA-00819 Views: 7485 0 Rating/ Voters

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

  1. void StreamAudio(LVSpeechPort port)
  2. {
  3. char* current_pos;
  4. int single_chunk = 160;
  5. int audio_processed = 0;

  6. current pos = audio_buffer;
  7. port.StreamStart();

  8. while(current_pos < audio_buffer + audio_size)
  9. {
  10. // If the next iteration would bring the audio stream past
  11. // the end of the buffer, set the amount to be streamed
  12. // equal to the remaining space in the buffer.
  13. if((audio_processed + single_chunk) > audio_size)
  14. single_chunk = audio_size - audio_processed;

  15. // Send data to the voicechannel and increment the current position.
  16. port.StreamSendData(current_pos, single_chunk);
  17. current_pos += single_chunk;
  18. audio_processed += single_chunk;
  19. Sleep((DWORD)(single_chunk / 8))
  20. }
  21. }

See Also