I have this code:
import numpy as np
import scipy.io.wavfile
import math
rate, data = scipy.io.wavfile.read('xenencounter_23.wav')
data2 = []
for i in range(len(data)):
data2.append([int(round(math.sin(data[i][0])*3000)), int(round(math.sin(data[i][1])*3000))])
data2 = np.asarray(data2)
print data2
scipy.io.wavfile.write('xenencounter_23sin3.wav',rate,data2)
This prints (truncated):
[[-2524 2728]
[ -423 -2270]
[ 2270 423]
...,
[-2524 0]
[ 2524 -2728]
[-2270 838]]
The wav file opens and plays in Windows Media Player, so at least its the proper format. However, when opening it with Audacity and looking at the individual samples, they're all 0, and concordantly the file plays no sound at all.
What I don't understand is how that numpy array listed above becomes all 0's. It should be below the maximum value for a sample (or above, if it's negative).
print data
statement after the linerate, data = scipy.io.wavfile.read('xenencounter_23.wav')
. I want to see what that data looks like. – Overtone[[-1 2] [-3 4] [-4 3] ..., [-1 0] [ 1 -2] [ 4 -6]]
However, in another part of the array it lists:[-2050 -1856] [-1814 -1621] [-1493 -1295] [-2042 -1848]
, so pretty similar – Oafscipy.io.wavfile.write('xenencounter_23sin3.wav',rate,data)
- you want to figure out if the write method or the operation you do on the data is the problem. – Overtone