Audio#

Load .wav file#

To load a wav file as a Document.

from docarray import Document

d = Document(uri='toy.wav').load_uri_to_audio_tensor()

print(d.tensor.shape, d.tensor.dtype)
(30833,) float32

Save as .wav file#

You can save Document .tensor as a .wav file:

d.save_audio_tensor_to_file('toy.wav')

Example#

Let’s load the “hello” audio file, reverse it and finally save it.

from docarray import Document

d = Document(uri='hello.wav').load_uri_to_audio_tensor()
d.tensor = d.tensor[::-1]
d.save_audio_tensor_to_file('olleh.wav')
hello.wav olleh.wav

Other tools & libraries for audio data#

By no means you are restricted to use DocArray native methods for audio processing. Here are some command-line tools, programs and libraries to use for more advanced handling of audio data:

  • FFmpeg is a free, open-source project for handling multimedia files and streams.

  • pydub: manipulate audio with a simple and easy high level interface

  • librosa: a python package for music and audio analysis.

  • pyAudioAnalysis: for IO or for more advanced feature extraction and signal analysis.