Exemplo n.º 1
0
def get_user_audio():
    '''
    Using pyaudio, this function takes in mic input and returns the respective midi pitch value.
    '''
    # instantiate PyAudio object
    p = pyaudio.PyAudio()

    # open mic stream
    mic = p.open(format=FORMAT,
                 channels=CHANNELS,
                 rate=RATE,
                 input=True,
                 frames_per_buffer=PERIOD_SIZE_IN_FRAME)

    # Initiating Aubio's pitch detection object.
    pDetection = aubio.pitch(METHOD, CHUNK, HOP_SIZE, RATE)
    # Set unit.
    pDetection.set_unit("Hz")
    # Frequency under 5 dB will considered
    # as a silence (8 dB is a C1 or midi#0)
    pDetection.set_silence(-40)

    data = mic.read(PERIOD_SIZE_IN_FRAME)
    # Convert into number that Aubio understand.
    samples = np.fromstring(data, dtype=aubio.float_type)
    # Finally get the pitch.
    pitch = pDetection(samples)[0]

    midi = freq2midi(pitch)

    mic.stop_stream()
    mic.close()
    p.terminate()

    return midi
Exemplo n.º 2
0
def representationToNote(representation_list):

	notes_list = []
	
	for i, representation in enumerate(representation_list):

		note_in_freq = representation[0]

		note_in_midi = int(freq2midi(note_in_freq))

		if note_in_midi < 0:
			note_in_midi = 0

		notes_list.append(note_in_midi)

	return notes_list
Exemplo n.º 3
0
def frequencyToNote(frequencies):
    tempList = frequencies.copy()

    for i in range(len(frequencies)):
        if frequencies[i] == None:
            tempList[i] = []
        else:
            tempList[i] = freq2midi(frequencies[i])
            j = 0
            k = 0
            while j < len(frequencies[i]) - k:
                if tempList[i][j] < 0 or tempList[i][j] >= 256:
                    tempList[i].remove(tempList[i][j])
                    j = 0
                    k += 1
                j += 1
    print(tempList)
    return tempList
Exemplo n.º 4
0
             channels=CHANNELS,
             rate=RATE,
             input=True,
             frames_per_buffer=PERIOD_SIZE_IN_FRAME)

# Initiating Aubio's pitch detection object.
pDetection = aubio.pitch(METHOD, CHUNK, HOP_SIZE, RATE)
# Set unit.
pDetection.set_unit("Hz")
# Frequency under 5 dB will considered
# as a silence (8 dB is a C1 or midi#0)
pDetection.set_silence(-40)

while mic.is_active():
    # Always listening to the microphone.
    data = mic.read(PERIOD_SIZE_IN_FRAME)
    print(data)
    # Convert into number that Aubio understand.
    samples = np.fromstring(data, dtype=aubio.float_type)
    # Finally get the pitch.
    pitch = pDetection(samples)[0]

    midi = freq2midi(pitch)

    print(str(pitch) + " " + str(midi))

mic.stop_stream()
mic.close()

p.terminate()