1

I am doing a project that uses sounddevice in order to record sound. I will also need to use the frequency and the volume of the sound for the project. I have figured out how to record sounds, but I am having trouble figure out how to manipulate the array that the recorded sound is stored as since I do not know what any of the values correspond to. I tried looking online to figure out how the arrays in sounddevice work, but the information either wasn't there or it did not make sense to me.

When I try printing the array I get this:

array([[ 0.0000000e+00,  0.0000000e+00],
       [-3.0517578e-05,  0.0000000e+00],
       [ 0.0000000e+00,  0.0000000e+00],
       ...,
       [-2.0446777e-02, -2.0416260e-02],
       [-1.3946533e-02, -1.3946533e-02],
       [ 2.7465820e-04,  2.7465820e-04]], dtype=float32)

This is a link to the documentation of sounddevice: https://python-sounddevice.readthedocs.io/en/0.3.15/

This is what I am using to record the sound:

import sounddevice as sd
#from scipy.io.wavfile import write
#from derivatives import slope
import numpy as np

fs = 45000
seconds = 1


test = input()
if test == '':
    myrecording = sd.rec(int(seconds * fs), samplerate=fs, channels=2)
    print('recording')
    sd.wait() 
    print('done recording')
#write('output.wav', fs, myrecording)
EMC
  • 91
  • 1
  • 7
  • 1
    Could you post the link to the documentation you found online ? – SimonR May 23 '20 at 19:15
  • Here is the link: https://python-sounddevice.readthedocs.io/en/0.3.15/ – EMC May 23 '20 at 19:26
  • 1
    Could you provide the code you used to make the recording ? – SimonR May 23 '20 at 20:23
  • I added the code that I am using to record my audio – EMC May 23 '20 at 22:03
  • 1
    From what I understand from the documentation and the code you posted, the two dimensions of the output array are the number of samples, and the number of channels. You can check this by doing `print(myrecording.shape)`, which should give `(45000, 2)`. The values then must be the amplitude of the sound wave at each point in time, on each channel. – SimonR May 24 '20 at 00:45
  • So does this mean that it is just saving the amplitudes of the sound waves and not explicitly the frequencies? – EMC May 25 '20 at 03:27
  • 1
    It looks that way. You'd need to apply a Fourier transform to change from the time domain to the frequency domain. – SimonR May 25 '20 at 11:15
  • Okay I see now. Thank you for your help! I will see what I can do with that. – EMC May 25 '20 at 20:40
  • @EMC If you solved your issue, can you post your answer? – S Andrew Nov 21 '22 at 10:32

0 Answers0