question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

librosa.output.write_wav doesn't accept int16 typed arrays

See original GitHub issue

Description

librosa.output.write_wav doesn’t accept int16 typed arrays, while it worked before. I found this is caused by #616, https://github.com/librosa/librosa/commit/f3114f280f5f9eaee5f2a69f90d3771b3d0eb5fa. Is this an intentional change or a bug?

Steps/Code to Reproduce

In [1]: import librosa; import numpy as np

In [2]: librosa.__version__
Out[2]: '0.5.1'

In [3]: x, sr = librosa.load(librosa.util.example_audio_file(), sr=None)

In [4]: librosa.output.write_wav("test.wav", (x * 32768).astype(np.int16), sr)
---------------------------------------------------------------------------
ParameterError                            Traceback (most recent call last)
<ipython-input-4-9736a6fc3adb> in <module>()
----> 1 librosa.output.write_wav("test.wav", (x * 32768).astype(np.int16), sr)

/home/ryuichi/Dropbox/python/librosa/librosa/output.py in write_wav(path, y, sr, norm)
    214 
    215     # Validate the buffer.  Stereo is okay here.
--> 216     util.valid_audio(y, mono=False)
    217 
    218     # normalize

/home/ryuichi/Dropbox/python/librosa/librosa/util/utils.py in valid_audio(y, mono)
    157 
    158     if not np.issubdtype(y.dtype, np.float):
--> 159         raise ParameterError('data must be floating-point')
    160 
    161     if mono and y.ndim != 1:

ParameterError: data must be floating-point

Expected Results

No errors.

Actual Results

As shown above.

Versions

In [5]: librosa.show_versions()
INSTALLED VERSIONS
------------------
python: 3.6.1 |Anaconda custom (64-bit)| (default, May 11 2017, 13:09:58) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]

librosa: 0.5.1

audioread: installed, no version number available
numpy: 1.13.3
scipy: 0.19.1
sklearn: 0.19.1
joblib: 0.11
decorator: 4.0.11
six: 1.11.0
resampy: 0.2.0

/home/ryuichi/anaconda3/lib/python3.6/site-packages/sphinx/util/compat.py:40: RemovedInSphinx17Warning: sphinx.util.compat.Directive is deprecated and will be removed in Sphinx 1.7, please use docutils' instead.
  RemovedInSphinx17Warning)
numpydoc: installed, no version number available
sphinx: 1.6.3
sphinx_rtd_theme: 0.2.4
sphinxcontrib.versioning: 2.2.1
matplotlib: 2.0.2
numba: 0.35.0+10.g143f70e90

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
stefan-balkecommented, Feb 12, 2018

I would keep it as is. If people need more flexibility they could use pysoundfile…maybe we should document that? 😃

1reaction
bmcfeecommented, Feb 13, 2018

Could this have changelog entry? This breaks some user code. e.g.,

Yes! Sorry for that – it’s linked in updated changelog for rc1, but I’ll make it more explicit for the final distribution. Note that doc build/deployment takes several hours, so you won’t see it right away in the main documentation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Advanced I/O Use Cases — librosa 0.10.0.dev0 documentation
This section covers advanced use cases for input and output which go beyond the I/O functionality currently provided by librosa. Read specific formats¶....
Read more >
How to generate audio from a numpy array? - Stack Overflow
I just needed to sudo apt-get install libsndfile1-dev . And on the other hand, sounddevice doesn't work for me: nothing is played when...
Read more >
SoundFile — PySoundFile 0.10.3post1-1-g0394588 ...
SoundFile represents audio data as NumPy arrays. ... Only the data types 'float64' , 'float32' , 'int32' and 'int16' are supported.
Read more >
ArrayBuffer, binary arrays - The Modern JavaScript Tutorial
Typed arrays behave like regular arrays: have indexes and are iterable. A typed array constructor (be it Int8Array or Float64Array , doesn't ......
Read more >
Typed Arrays in ECMAScript 6 - 2ality
works much like a normal Array, but only allows a single type for its elements and doesn't have holes. An instance of DataView...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found