-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgamma_binaural.py
54 lines (46 loc) · 1.37 KB
/
gamma_binaural.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from AccelBrainBeat.brainbeat.binaural_beat import BinauralBeat
from pydub import AudioSegment
import numpy as np
import wave_func as wf
import os
total_time_min = 30
total_time = 60*total_time_min
samprate = 44100
length = 2 ** 17
tmp = np.random.random(size=length) * 2 - 1
S = np.fft.rfft(tmp)
fil = 1 / (np.arange(len(S))+1)
S = S * fil
s = np.fft.irfft(S)
s /= np.max(np.abs(s))
c = np.concatenate([s for n in range(60)])
wf.write_wave("/tmp/pinknoise.wav", c, fs=samprate)
noise = AudioSegment.empty()
for n in range(total_time_min):
noise += AudioSegment.from_wav("/tmp/pinknoise.wav")
noise = noise.set_channels(2)
noise = noise - 15
noise = noise[:60*1000*total_time_min]
noise.export("pinknoise.wav", format="wav")
file_name = "/tmp/gamma.wav"
brain_beat = BinauralBeat()
brain_beat.save_beat(
output_file_name="/tmp/1.wav",
frequencys=(528, 567),
play_time=total_time,
volume=0.3
)
brain_beat.save_beat(
output_file_name="/tmp/2.wav",
frequencys=(417, 447),
play_time=total_time,
volume=0.3
)
sound1 = AudioSegment.from_file("/tmp/1.wav")
sound2 = AudioSegment.from_file("/tmp/2.wav")
output = sound1.overlay(sound2, position=0)
output.export(file_name, format="wav")
combined_wav = AudioSegment.empty()
combined_wav += AudioSegment.from_wav(file_name)
output = noise.overlay(combined_wav, position=0)
output.export("gamma_noise.wav", format="wav")