過去胡適先生寫了一篇《讀書》── 談讀書四到 ── 眼到,口到,心到,手到 ── 對今天的學子來說依然十分有益。
⊙ㄚ!!『讀書』一事,怎是一個□字了得?『讀錯了書』是書不好 ,『錯讀得書』是讀不好。該如何是好?也許有個順口溜,能夠回答這個問題︰
好讀不?不好ㄏㄠˇ讀,所以讀不好。
不讀好,考不好!怕是不好ㄏㄠˋ讀。
─── 要是好,需是了,不了就不好 ─── 紅樓夢
─── 《讀錯□書⊙錯讀□書》
若人與『錯誤』不期而遇︰
ParameterError: Input buffer must be contiguous.
或許指明『讀時不了』之事︰
librosa.display.waveplot
librosa.display.
waveplot
(y, sr=22050, max_points=50000.0, x_axis=’time’, offset=0.0, max_sr=1000, **kwargs)- Plot the amplitude envelope of a waveform.
If y is monophonic, a filled curve is drawn between [-abs(y), abs(y)].
If y is stereo, the curve is drawn between [-abs(y[1]), abs(y[0])], so that the left and right channels are drawn above and below the axis, respectively.
Long signals (duration >= max_points) are down-sampled to at most max_sr before plotting.
Parameters: y : np.ndarray [shape=(n,) or (2,n)]
audio time series (mono or stereo)
恰是『補過』之時?!
Advanced I/O Use Cases
This section covers advanced use cases for input and output which go beyond the I/O functionality currently provided by librosa.
Read specific formats
librosa uses audioread for reading audio. While we chose this library for best flexibility and support of various compressed formats like MP3: some specific formats might not be supported. Especially specific WAV subformats like 24bit PCM or 32bit float might cause problems depending on your installed audioread codecs. libsndfile covers a bunch of these formats. There is a neat wrapper for libsndfile called PySoundFile which makes it easy to use the library from python.
Note
See installation instruction for PySoundFile here.
Reading audio files using PySoundFile is similmar to the method in librosa. One important difference is that the read data is of shape (nb_samples, nb_channels)
compared to (nb_channels, nb_samples)
in <librosa.core.load>
. Also the signal is not resampled to 22050 Hz by default, hence it would need be transposed and resampled for further processing in librosa. The following example is equivalent to librosa.load(librosa.util.example_audio_file())
:
import librosa import soundfile as sf # Get example audio file filename = librosa.util.example_audio_file() data, samplerate = sf.read(filename, dtype='float32') data = data.T data_22k = librosa.resample(data, samplerate, 22050)
正好『反省思辨』也!?