Send data buffer of sound data to stream.
Function
- int LV_SRE_StreamSendData(HPORT hport, void* SoundData, int SoundDataLength)
Parameters
hport
The port's handle.
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_INVALID_HPORT
The input hport is not a valid one.
LV_FAILURE
The operation failed because the port was shutting down.
LV_STREAM_NOT_ACCEPTED
The data was not accepted, likely because the port was not ready to receive data. Ensure that LV_SRE_StreamStart was called first.
LV_EXCEPTION
An exception occurred while processing the request.
Remarks
This function is used to do the actual streaming. Call it with each filled sound data buffer. 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
- // Here, audio_length is the length of the audio file being streamed.
- // pStreamingUserData contains information about the given audio stream.
- unsigned char* audio_buffer = (unsigned char*)malloc(audio_length);
- unsigned char* CurrentPos = audio_buffer;
- int StreamedBytes = 0;
- int ChunkBytes = 2400;
- while (CurrentPos != (audio_buffer + audio_length))
- {
- if (pStreamingUserData->StopStreaming == true)
- pStreamingUserData->Streaming = -1;
- // Check to see if streaming has stopped; if so, break. Next, make sure
- // that you are not trying to send in more than the entire length of the
- // audio. Once these conditions are accounted for, then you can pass the
- // audio chunk to the ASR.
- SpeechPortReturnValue = LV_SRE_StreamSendData(
- pStreamingUserData->PortHandle, CurrentPos, ChunkBytes);
- // Sleep to allow streaming to finish.
- SLEEP_MS(ChunkBytes/8)
- // Make another check to see if streaming has stopped
- // Finally, append the amount we just passed to our total so far, and
- // move the current position accordingly
- StreamedBytes += ChunkBytes;
- CurrentPos += ChunkBytes;
- }
See Also