Playing Audio In Jupyter, In A For Loop
I have a ton of training data I need annotated, in order to do so I need to listen through a bunch of sound snippets and note what I hear. I wrote a small script for this in a notebook.
My main issue is that IPython display dosent show in loops. As an example:
import numpy import IPython.display as ipd sr = 22050# sample rate T = 2.0# seconds t = numpy.linspace(0, T, int(T*sr), endpoint=False)# time variable x = 0.5*numpy.sin(2*numpy.pi*440*t) ipd.Audio(x, rate=sr)
will show up with an audio box, and I will be able to play the sine wave.
But trying to play anything in a for loop yields nothing (such as:)
for i in range(10000000): x = 0.5*numpy.sin(i*numpy.pi*440*t) ipd.Audio(x, rate=sr)
If anyone has a good solution for looping through (and listening) a bunch of audio files (one at a time, since I need to loop through potentially hundreds of thousands sound snippets), I would be very much appreciative!
To display the audio files within the for loop, you need to use
IPython.display.display with the
Audio object like so:
import numpy import IPython.display as ipd for i in range(10000000): x = 0.5*numpy.sin(i*numpy.pi*440*t) ipd.display(ipd.Audio(x, rate=sr))
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Django, code inside <script> tag doesn't work in a template
- → React - Django webpack config with dynamic 'output'
- → GAE Python app - Does URL matter for SEO?
- → Put a Rendered Django Template in Json along with some other items
- → session disappears when request is sent from fetch
- → Python Shopify API output formatted datetime string in django template
- → Shopify app: adding a new shipping address via webhook
- → Shopify + Python library: how to create new shipping address
- → shopify python api: how do add new assets to published theme?
- → Access 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' with Python Shopify Module