Skip to content

Fix detect silence to work with smaller audio chunks #296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

kimberlysiva
Copy link
Contributor

Now that we're using smaller audio chunks it isn't safe to discard individual silent chunks. I propose tracking the duration of the silence, and only sending a stop once we reach a specified duration. For now I've chosen 1.0 second, but smaller values might work as well. All silent audio chunks will be discarded after this cutoff, until a non-silent chunk is encountered.

@@ -177,7 +177,7 @@ private IEnumerator RecordingHandler()

// Create AudioData and use the samples we just created
AudioData record = new AudioData();
record.MaxLevel = Mathf.Max(samples);
record.MaxLevel = Mathf.Abs(Mathf.Max(samples));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @cloudconstable suggested this will only get highest positive values and was worried if we have a sample that is completely negative. I don't know enough about audio to understand what the samples look like but heres a fix for that

record.MaxLevel = Mathf.Max(Mathf.Abs(Mathf.Min(samples)), Mathf.Max(samples));

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course! Good catch, I'll change this.

@mediumTaj mediumTaj merged commit 3b09eeb into watson-developer-cloud:gh279-streaming-example Nov 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants