jupyter-widgets / pythreejs

A Jupyter - Three.js bridge
https://pythreejs.readthedocs.io
Other
934 stars 185 forks source link

Playing audio with pythreejs? #339

Open nthiery opened 3 years ago

nthiery commented 3 years ago

I have tried to reproduce the following threejs example in pythreejs, but with no success yet:

https://threejs.org/docs/#api/en/audio/Audio

import pythreejs
audioLoader = pythreejs.AudioLoader()
audioLoader.load("http://nicolas.thiery.name/sol.ogg")
AttributeError: 'AudioLoader' object has no attribute 'load'

Similarly, the Audio constructor takes no argument, etc.

Has anyone managed to play sound with pythreejs?

vidartf commented 3 years ago

The audio classes have not been specced out yet:

https://github.com/jupyter-widgets/pythreejs/blob/5857d541c0109ecacf64c2f515b1e446da6f1a30/js/scripts/three-class-config.js#L77-L91

For context: Is there a reason to prefer the pythreejs audio over IPython.display.Audio or ipywebrtc ?

nthiery commented 3 years ago

Hi Vidar! Thanks for the feedback.

Context: I am building a widget to display and analyze musical juggling patterns. To this end, I am toying out with threejs's animation capabilities (with AnimationClip ...) to animate the balls moving in the air. It's pretty fun to play with these capabilities!

Now, for the musical aspect, I need to play audio at certain times in the animation. This called for a pythreejs solution, but other option would certainly do.

If at all possible, I would like a solution that can be controlled purely from the Python side. For simplicity of deployment; because I am very slow at anything javascript; and also to empower the end users for whom Python is already a serious step.

The most versatile tool would be the ability to setup a callback to Python at certain times in the animation. Does pythreejs enable something like this?

Tips most welcome :-)

(sorry for the topic deviation in this issue)