Skip to content

Sound.play_file not producing any audio #760

Closed

Description

@drew-linerud
  • ev3dev version:
    4.14.117-ev3dev-2.3.5-ev3

  • ev3dev-lang-python version:
    ||/ Name Version Architecture Description
    +++-==============-============-============-=================================
    ii micropython-ev 2.1.0 all Python language bindings for ev3d
    ii python3-ev3dev 1.2.0 all Python language bindings for ev3d
    ii python3-ev3dev 2.1.0 all Python language bindings for ev3d

Hi, I'm not able to play audio from a wav file using Sound.play_file. Here's the code:

from ev3dev2.sound import Sound
my_sound = Sound()
my_sound.speak('Hello?')
my_sound.play_file('Recording.wav', 100, Sound.PLAY_LOOP)
my_sound.speak('Done')

If I don't include Sound.PLAY_LOOP in play_file, then the program completes successfully, just never playing the audio in Recording.wav. With PLAY_LOOP specified, the script speaks "Hello?" and then runs indefinitely without making another sound.

I also tried specifying the full path to Recording.wav which didn't seem to make any difference. I verified that the file is on the device in the same folder with the script.

Am I doing something wrong, or is this a bug? Attaching a zip file with my small .wav file.

audio.zip

Activity

  1. WasabiFan commented on Aug 21, 2020

    @WasabiFan
    Member

    Internally, play_file uses the aplay command. Could you try running this command and see if it is able to play your file? If not, are there any error messages?

    /usr/bin/aplay path/to/Recording.wav
    
  2. dlech commented on Aug 21, 2020

    @dlech
    Member

    Try normalizing the sound to make it as loud as possible. Currently, the peaks are a small fraction of the available range.

    image

    Also, 16-bit, mono, 22050Hz sound format works best, otherwise the CPU on the EV3 has to do extra processing to convert the format on the fly.

  3. drew-linerud commented on Aug 21, 2020

    @drew-linerud
    Author

    Converting to 16-bit mono, 22050 Hz (352,800 bit rate) allowed it to work. Thanks for the quick answer!
    Would be awesome to add that format to the documentation.

  4. added a commit that references this issue on Aug 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions