zayfod / pycozmo

A pure-Python communication library, alternative SDK, and application for the Cozmo robot.
MIT License
173 stars 58 forks source link

Included Audio Manager class #20

Closed gimait closed 3 years ago

gimait commented 3 years ago

This PR is related to #11.

Cozmo uses packets including 744 samples of u-law encoded data to reproduce 22kHz audio recordings.

Changes in this PR:

Please check out the changes in conn. I am not familiar with network communications so I am not sure whether there are any patterns that can be used generally to resend packets (or frames).

Currently, only 16 bit samples have been tested, but it should also be possible to send 8 bit samples also. The audio is limited to 22kHz. For 44 or 48kHz files, only one of every two samples is used. It is possible to use files with 1 or 2 channels (although only the first one will be used). Only .wav files are supported, but if necessary, the functionality to load other files could be included in the future.

In the future, it would be good to include a method to allow playing a bytes object from memory, this would make it possible to include some text-to-speech capabilities to the robot.

gimait commented 3 years ago

I reverted the changes related to the SendThread, and made some changes to the AudioManager. I would suggest waiting until we have running the resend packages to finish up this PR, if that is okay with you. Let me know what you think about it when you have time. ( I also saw that some checks are failing, I'll take a look at that too)

zayfod commented 3 years ago

I finally tried this and it works great!

Hats off for figuring audio out.

gimait commented 3 years ago

I'm very happy to see this working too! And hey, the audio was nothing, hats off to you for making this amazing library!