Giter Site home page Giter Site logo

Jupyter Backend about pya HOT 7 CLOSED

aleneum avatar aleneum commented on June 10, 2024
Jupyter Backend

from pya.

Comments (7)

wiccy46 avatar wiccy46 commented on June 10, 2024

I am getting the same error on Safari: ReferenceError: Can't find variable: AudioContext

Internet says safari needs webkit as the prefix to AudioContext. But it seems you already set that in Line 104 Jupyter.py

from pya.

wiccy46 avatar wiccy46 commented on June 10, 2024

In the "Normalize signal amplitude and set gain" example:

for n in [1, 0.5, 0.1, -6, -12, -18, -24, -30, -36, -42]:
    asnap[{0.1:0.4}].norm(n).play(block=True)

ps. add a gain to not blow your ears off: asnap[{0.1:0.4}].norm(n).gain(db=-40).play(block=True)

It was supposed to be played one after another due to block. In python, when block, time.sleep(asig.get_duration()) is executed in Aserver after audio is being pushed to the callback loop. But due to the delay in webaudio, all the samples ended up being push in roughly the same time (coz asnap is very short), resulting a big burst of noise.

This also mean that there to the issue of sequencing audios under Jupyter backend. With PyAudio, play() without onset will just assume the sound is play 'instantly'. I am not sure how we can solve this with Web Audio since the delay is unpredictable.

from pya.

aleneum avatar aleneum commented on June 10, 2024

ps. add a gain to not blow your ears off: asnap[{0.1:0.4}].norm(n).gain(db=-40).play(block=True)

the problem here is that pya blocks the main thread and prevents the async ioloop to process events.

But due to the delay in webaudio, all the samples ended up being push in roughly the same time (coz asnap is very short), resulting a big burst of noise.

the backend delay is completely transparent and also rather consistent which means that latency/delay sums up just the same way as when it is played locally. As mentioned above, the actual problem is using time.sleep. This only works for PyAudio because callbacks are actually handled in threads. A way better solution would be to make use of await here to free the main thread.

from pya.

aleneum avatar aleneum commented on June 10, 2024

I am getting the same error on Safari: ReferenceError: Can't find variable: AudioContext

good catch, should be fixed in the last commit to feature-jupyter

from pya.

aleneum avatar aleneum commented on June 10, 2024

Safari has some quirks that needs special, handling. When using Safari, we need to resume the WebAudioContext in a user triggered event. I have chosen focus events which happen when you click on a code cell since I assumed this will be a very likely and natural user interaction. Also I put the webserver into a thread to make it behave like PyAudio even though i think asyncio and awaiting events would be the more suitable choice for pya. What remains is the offset of blocked events which will have a (probably static) overlap due to the latency. This will slightly increase the signals volume over time for code snippets as mentioned above. I Imho, this is nevertheless good enough as the JupyterBackend has never been intended to be a full featured replacement for PyAudio. Having the opportunity to test pya in the browser without the need of installing anything is a big convenience gain in my book. Solutions such as 'instant play' as suggested by @thomas-hermann might event improve the user experience for remote operation in the future even further.

from pya.

aleneum avatar aleneum commented on June 10, 2024

considering lag. a solution could be to distinguish between "pya time" and "backend time" by preparing chunks to be played outside of the playback callbacks or at least make the preparation agnostic towards timing. A similar check than what is happening in _playback_callback is also implemented in the javascript client. So maybe pushing the time check to the PyAudio backend and let pya assume correct timing makes this more flexible.

from pya.

aleneum avatar aleneum commented on June 10, 2024

closing this since it has been merged into master. we still need to check how to deal with the timing issue.

from pya.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.