How to generate audio from a numpy array?

后端 未结 8 867
囚心锁ツ
囚心锁ツ 2020-11-28 04:09

I want to create \"heart rate monitor\" effect from a 2D array in numpy and want the tone to reflect the values in the array.

相关标签:
8条回答
  • 2020-11-28 05:08

    Not sure of the particulars of how you would produce the audio from the array, but I have found mpg321 to be a great command-line audio player, and could potentially work for you.

    I use it as my player of choice for Anki, which is written in python and has libraries that could be a great starting place for interfacing your code/arrays with audio.

    Check out:

    • anki.sound.py
    • customPlayer.py
    0 讨论(0)
  • 2020-11-28 05:15

    Another modern and convenient solution is to use pysoundfile, which can read and write a wide range of audio file formats:

    import numpy as np
    import soundfile as sf
    
    data = np.random.uniform(-1, 1, 44100)
    sf.write('new_file.wav', data, 44100)
    
    0 讨论(0)
提交回复
热议问题