Skip to content

Commit

Permalink
#1 Multi Part responses from the assistant can lead to the data recei…
Browse files Browse the repository at this point in the history
…ved not being the max number of bytes but have follow on audio. So remove the 1600 byte hack.
  • Loading branch information
ac87 committed May 10, 2017
1 parent 3544dde commit f6376f9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
10 changes: 7 additions & 3 deletions Assistant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,11 @@ private async Task WaitForResponse()
OnDebug?.Invoke(ResponseToOutput(currentResponse));

// EndOfUtterance, Assistant has recognised something so stop sending audio
if (currentResponse.EventType == ConverseResponse.Types.EventType.EndOfUtterance)
if (currentResponse.EventType == ConverseResponse.Types.EventType.EndOfUtterance)
ResetSendingAudio(false);

if (currentResponse.AudioOut != null)
_audioOut.Play(currentResponse.AudioOut.AudioData.ToByteArray());
_audioOut.AddBytesToPlay(currentResponse.AudioOut.AudioData.ToByteArray());

if (currentResponse.Result != null)
{
Expand All @@ -195,7 +195,7 @@ private async Task WaitForResponse()
_assistantResponseReceived = true;

switch (currentResponse.Result.MicrophoneMode)
{
{
// this is the end of the current conversation
case ConverseResult.Types.MicrophoneMode.CloseMicrophone:
StopRecording();
Expand All @@ -218,7 +218,11 @@ private async Task WaitForResponse()
await WaitForResponse();
}
else
{
OnDebug?.Invoke("Response End");
// if we've received any audio... play it.
_audioOut.Play();
}
}

private void ResetSendingAudio(bool send)
Expand Down
12 changes: 7 additions & 5 deletions AudioOut.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public class AudioOut
private WaveOut _waveOut;

private MemoryStream _ms;
private RawSourceWaveStream _waveStream;
private RawSourceWaveStream _waveStream;

public void Play(byte[] bytes)
public void AddBytesToPlay(byte[] bytes)
{
if (_waveOut == null)
{
Expand All @@ -36,10 +36,12 @@ public void Play(byte[] bytes)
if (_ms == null)
_ms = new MemoryStream();

_ms.Write(bytes, 0, bytes.Length);
_ms.Write(bytes, 0, bytes.Length);
}

// cheat, I know at the bitrate requested it splits it in this size chunks, if its not this size its the end
if (bytes.Length != 1600)
public void Play()
{
if (_ms != null && _ms.Length > 0)
{
_ms.Position = 0;
_waveStream = new RawSourceWaveStream(_ms, WaveFormat);
Expand Down

0 comments on commit f6376f9

Please sign in to comment.