diff --git a/production/.idea/inspectionProfiles/Project_Default.xml b/production/.idea/inspectionProfiles/Project_Default.xml
new file mode 100644
index 0000000..0384f59
--- /dev/null
+++ b/production/.idea/inspectionProfiles/Project_Default.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/production/.idea/misc.xml b/production/.idea/misc.xml
new file mode 100644
index 0000000..f946d59
--- /dev/null
+++ b/production/.idea/misc.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/production/.idea/modules.xml b/production/.idea/modules.xml
new file mode 100644
index 0000000..c011ac2
--- /dev/null
+++ b/production/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/production/.idea/production.iml b/production/.idea/production.iml
new file mode 100644
index 0000000..6711606
--- /dev/null
+++ b/production/.idea/production.iml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/production/.idea/workspace.xml b/production/.idea/workspace.xml
new file mode 100644
index 0000000..489cae3
--- /dev/null
+++ b/production/.idea/workspace.xml
@@ -0,0 +1,391 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ true
+ DEFINITION_ORDER
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1524583355197
+
+
+ 1524583355197
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/production/listener.py b/production/listener.py
index c0b668d..160b492 100644
--- a/production/listener.py
+++ b/production/listener.py
@@ -8,6 +8,7 @@
from multiprocessing.dummy import Queue, Process, Value
from aubio import notes, onset, tempo
from structures import Note, Chord
+import wave
"""
1 beat in bpm is 1/4 of musical beat
@@ -38,6 +39,10 @@ def run_queue_in(listener):
input=True,
frames_per_buffer=buffer_size)
+ listener.wavefile.setnchannels(n_channels)
+ listener.wavefile.setsampwidth(p.get_sample_size(pyaudio_format))
+ listener.wavefile.setframerate(sample_rate / 2)
+
notes_o = notes("default", win_s, hop_s, sample_rate)
onset_o = onset("default", win_s, hop_s, sample_rate)
temp_o = aubio.tempo("specdiff", win_s, hop_s, sample_rate)
@@ -49,9 +54,14 @@ def run_queue_in(listener):
prev_time = 0
while (listener.runing.value):
# read data from audio input
- audiobuffer = stream.read(buffer_size, exception_on_overflow = False)
+ audiobuffer = stream.read(buffer_size, exception_on_overflow=False)
samples = np.fromstring(audiobuffer, dtype=np.float32)
+ ##voice recording
+ converted_samples = np.int16((samples + 1) * (2 ** 16))
+ listener.wavefile.writeframes(bytes(converted_samples))
+ ##finish of voice recording
+
if (onset_o(samples)):
last_onset = onset_o.get_last_ms()
if (temp_o(samples)):
@@ -66,11 +76,13 @@ def run_queue_in(listener):
prev_time = last_onset
class Listener:
- def __init__(self, queue=Queue(), runing=Value('i', False), tempo=Value('i', default_tempo), deadline=Value('f', max_time)):
+ def __init__(self, queue=Queue(), runing=Value('i', False), tempo=Value('i', default_tempo),
+ deadline=Value('f', max_time), name_of_voice="your_voice.wav"):
self.queue_in = queue
self.runing = runing
self.tempo = tempo
- self.deadline = deadline
+ self.deadline = deadline
+ self.wavefile = wave.open(name_of_voice, "w")
def run(self):
self.runing.value = True
@@ -81,6 +93,7 @@ def stop(self):
self.runing.value = False
self.process.join()
self.queue_in = Queue()
+ self.wavefile.close()
def get(self):
if self.queue_in.empty() is False:
diff --git a/production/tmp.py b/production/tmp.py
new file mode 100644
index 0000000..0915122
--- /dev/null
+++ b/production/tmp.py
@@ -0,0 +1,69 @@
+
+import pyaudio
+import numpy as np
+import aubio
+
+from mido import Message, MidiFile, MidiTrack
+import wave
+from aubio import notes, onset, tempo
+
+
+sample_rate = 44100
+win_s = 2048
+hop_s = win_s // 4
+buffer_size = hop_s
+
+
+p = pyaudio.PyAudio()
+# open stream
+pyaudio_format = pyaudio.paFloat32
+n_channels = 1
+stream = p.open(format=pyaudio_format,
+ channels=n_channels,
+ rate=sample_rate,
+ input=True,
+ frames_per_buffer=buffer_size)
+
+wavefile = wave.open("your_voice.wav", "w")
+wavefile.setnchannels(n_channels)
+wavefile.setsampwidth(p.get_sample_size(pyaudio_format))
+wavefile.setframerate(sample_rate / 2)
+
+notes_o = notes("default", win_s, hop_s, sample_rate)
+onset_o = onset("default", win_s, hop_s, sample_rate)
+
+max = 300
+cnt = 0
+last_onset = 0
+
+mid = MidiFile()
+tracks = []
+num = 0
+while (cnt < max):
+ # read data from audio input
+ audiobuffer = stream.read(buffer_size, exception_on_overflow=False)
+ print(audiobuffer)
+ samples = np.fromstring(audiobuffer, dtype=np.float32)
+ prom = np.int16((samples + 1) * (2**16))
+ print(prom)
+ toOut = bytes(prom)
+ wavefile.writeframes(toOut)
+ cnt += 1
+ if (onset_o(samples)):
+ last_onset = int(onset_o.get_last_ms())
+ new_note = notes_o(samples)
+ if (new_note[0] != 0):
+ tracks.append(MidiTrack())
+ mid.tracks.append(tracks[num])
+ new_note[0] = int(new_note[0])
+ tracks[num].append(Message('program_change', program=33, time=10))
+ nn = int(new_note[0])
+ tracks[num].append(Message('note_on', note=nn, velocity=124, time=last_onset))
+ tracks[num].append(Message('note_off', note=nn, velocity=0, time=int(new_note[1])))
+ tracks[num].append(Message('note_on', note=(nn + 12) % 128, velocity=124, time=last_onset))
+ tracks[num].append(Message('note_off', note=(nn + 12) % 128, velocity=0, time=int(new_note[1])))
+ num += 1
+ print(cnt)
+
+wavefile.close()
+mid.save('zmey.midi')
diff --git a/production/your_voice.wav b/production/your_voice.wav
new file mode 100644
index 0000000..774caa9
Binary files /dev/null and b/production/your_voice.wav differ
diff --git a/production/zmey.midi b/production/zmey.midi
new file mode 100644
index 0000000..974618f
Binary files /dev/null and b/production/zmey.midi differ