在jupyter的for循环中播放音频 [英] Playing audio in jupyter, in a for loop

查看:506
本文介绍了在jupyter的for循环中播放音频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有大量需要注释的训练数据,为此,我需要听一堆声音片段并记下我听到的声音.我在笔记本上为此写了一个小脚本.

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.

我的主要问题是IPython显示循环显示.例如:

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.

但是尝试在for循环中播放任何内容都不会产生任何结果(例如:)

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!

推荐答案

要在for循环中显示音频文件,您需要将IPython.display.displayAudio对象一起使用,如下所示:

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))

这篇关于在jupyter的for循环中播放音频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆