1. 程式人生 > 其它 >Python 立體聲音訊生成

Python 立體聲音訊生成

技術標籤:語音訊號處理音訊訊號處理

  1. pip安裝依賴

    pip install wave
    pip install numpy
    pip install soundfile
    
  2. 立體聲音訊生成示例程式碼

    import wave
    import numpy as np
    import soundfile as sf
       
    # read wave files
    left_data, _ = sf.read("test_1.wav")
    right_data, _ = sf.read("test_2.wav")
       
    # A 2D array where the left and right tones are contained in their respective rows
    stereo = np.vstack((left_data, right_data))
       
    # Reshape 2D array so that the left and right tones are contained in their respective columns
    stereo = stereo.transpose()
       
    sf.write('stereoAudio.wav', stereo, samplerate=44100)