最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - Can't hear Librosa chirp - Stack Overflow

programmeradmin2浏览0评论

I am using python under VS. When running the following code

import librosa
from IPython.display import Audio
sr = 22050

y_sweep = librosa.chirp(fmin=librosa.note_to_hz('C3'),
                    fmax=librosa.note_to_hz('C5'),
                    sr=sr,
                    duration=5)

Audio(data=y_sweep, rate=sr)`

I CAN NOT hear any sound. The windows speakers are OK Volume is set loud. and the default player is Windows media player (works OK). I don't get any error message. On another similar code when using the

img = librosa.display.specshow 

(.... it works OK, but again with no actual sound.)

I was expecting to hear. The code is taken from .html#sphx-glr-auto-examples-plot-audio-playback-py. When using the play button on the above site, sound is correctly heard.

I am using python under VS. When running the following code

import librosa
from IPython.display import Audio
sr = 22050

y_sweep = librosa.chirp(fmin=librosa.note_to_hz('C3'),
                    fmax=librosa.note_to_hz('C5'),
                    sr=sr,
                    duration=5)

Audio(data=y_sweep, rate=sr)`

I CAN NOT hear any sound. The windows speakers are OK Volume is set loud. and the default player is Windows media player (works OK). I don't get any error message. On another similar code when using the

img = librosa.display.specshow 

(.... it works OK, but again with no actual sound.)

I was expecting to hear. The code is taken from https://librosa./doc/main/auto_examples/plot_audio_playback.html#sphx-glr-auto-examples-plot-audio-playback-py. When using the play button on the above site, sound is correctly heard.

Share Improve this question asked Mar 31 at 17:33 Jacob SternJacob Stern 1 New contributor Jacob Stern is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
Add a comment  | 

1 Answer 1

Reset to default 0

IPython audio playback works only in Jupyter Notebooks. If you run standard Python, you need some other solution for playing audio. sounddevice is suitable for you, it can play audio from a numpy array

Install via pip:

$ pip install sounddevice

Then replace IPython Audio(...) with sounddevice audio playing:

import librosa
import sounddevice

sr = 22050

y_sweep = librosa.chirp(
    fmin=librosa.note_to_hz("C3"), fmax=librosa.note_to_hz("C5"), sr=sr, duration=5
)

sounddevice.play(data=y_sweep, samplerate=sr)
sounddevice.wait() # don't fet to wait for audio playback to complete
发布评论

评论列表(0)

  1. 暂无评论