Skip to content

Fix audiodevice output buffer underrun error - #309

Merged
aaronchantrill merged 4 commits into
NaomiProject:naomi-devfrom
aaronchantrill:audioengine
Jan 13, 2021
Merged

aaronchantrill merged 4 commits into
NaomiProject:naomi-devfrom
aaronchantrill:audioengine

Conversation

@aaronchantrill

Copy link
Copy Markdown
Contributor

Description

After the latest Raspbian Buster update on my Raspberry Pi 4, I
was getting the following error message:

ALSA lib pcm.c:8424:(snd_pcm_recover) underrun occurred

This was causing Naomi to make raspberry noises instead of
talking when trying to play audio generated from flite.

I tried increasing the chunk size in the profile.yml file, but
it did not seem to affect the playback of a file in play_fp. It
looks like the chunksize and output padding both get written to
attributes of the audioengine plugin but I didn't see anywhere
that they were actually passed to the play_file or play_fp
audiodevice methods. Since we can read the profile directly from
any method just by including the profile module, I'm just reading
them directly from the play_fp method.

Increasing the chunk size worked, but the audio kept getting
clipped at the end. I tried enabling the padding option in
profile.yml, but that didn't help. I ended up adding a new
option under audio -> output_pause to have the computer pause
after the last chunk is written to the device and before the
stream is closed, and that finally worked. I set it to 0.5
seconds on my system which seemed to work fine. 0.1 was not
enough to prevent clipping.

Related Issue

Buffer Underrun errors #308

Motivation and Context

I was experiencing buffer underrun errors when my Naomi was speaking using flite for tts, pyaudio for the audio engine and pulse for the audio device. This problem only showed up after the latest update of Raspbian.

How Has This Been Tested?

I tested on my Raspberry Pi 4. I ran the unittests afterwards and everything passed.

(Naomi) ~/Naomi $ python -m unittest discover
----------------------------------------------------------------------
Ran 23 tests in 7.440s

OK (skipped=10)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Just a slight change to the Naomi TTI scoring. After generating
scores for all the intents, add those scores up and divide
individual scores by the total. This makes the score always fall
between 0 and 1 (currently there is no upper limit and I have
seen scores as high as between 6 and 7).

This should also make Naomi more confident in some cases. Right
now if one intent scores .01 and all the other intents are zero,
Naomi will respond with "unclear" since no intent has scored
above .05 (5%). With this new system, .01/.01=1 (100%). I don't
know if this will turn out to be a good thing or not. I think
it will be good, but if it causes problems, we might need to add
a filter before the conversion.
After the latest Raspbian Buster update on my Raspberry Pi 4, I
was getting the following error message:

ALSA lib pcm.c:8424:(snd_pcm_recover) underrun occurred

This was causing Naomi to make raspberry noises instead of
talking when trying to play audio generated from flite.

I tried increasing the chunk size in the profile.yml file, but
it did not seem to affect the playback of a file in play_fp. It
looks like the chunksize and output padding both get written to
attributes of the audioengine plugin but I didn't see anywhere
that they were actually passed to the play_file or play_fp
audiodevice methods. Since we can read the profile directly from
any method just by including the profile module, I'm just reading
them directly from the play_fp method.

Increasing the chunk size worked, but the audio kept getting
clipped at the end. I tried enabling the padding option in
profile.yml, but that didn't help. I ended up adding a new
option under  audio -> output_pause to have the computer pause
after the last chunk is written to the device and before the
stream is closed, and that finally worked. I set it to 0.5
seconds on my system which seemed to work fine. 0.1 was not
enough to prevent clipping.
@aaronchantrill aaronchantrill self-assigned this Jan 4, 2021
@aaronchantrill aaronchantrill linked an issue Jan 4, 2021 that may be closed by this pull request
@aaronchantrill
aaronchantrill merged commit 3e31688 into NaomiProject:naomi-dev Jan 13, 2021
@aaronchantrill
aaronchantrill deleted the audioengine branch January 13, 2021 14:34
aaronchantrill added a commit to aaronchantrill/Naomi that referenced this pull request Jan 23, 2021
In pull request NaomiProject#309, I removed the chunksize and add_padding
optional parameters from play_fp, and pulled those values
directly from the profile.

This worked fine in normal operation, but introduced issues with
the configuration routines in application.py which are passing
parameters to play_file which are being passed along to play_fp.

This update restores legacy compatibility by using *args and
**kwargs to allow values to be passed in optionally, which makes
it compatible with the call from play_file. If chunksize and
add_padding are passed in as keyword arguments for some reason,
those values are used instead of the profile values. In general,
developers should not pass values directly to play_file or play_fp.

I also removed the parameters from the play_file calls in
application.py.
@aaronchantrill aaronchantrill mentioned this pull request Jan 23, 2021
3 of 8 tasks
aaronchantrill added a commit that referenced this pull request Jan 23, 2021
In pull request #309, I removed the chunksize and add_padding
optional parameters from play_fp, and pulled those values
directly from the profile.

This worked fine in normal operation, but introduced issues with
the configuration routines in application.py which are passing
parameters to play_file which are being passed along to play_fp.

This update restores legacy compatibility by using *args and
**kwargs to allow values to be passed in optionally, which makes
it compatible with the call from play_file. If chunksize and
add_padding are passed in as keyword arguments for some reason,
those values are used instead of the profile values. In general,
developers should not pass values directly to play_file or play_fp.

I also removed the parameters from the play_file calls in
application.py.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Buffer Underrun errors

1 participant