Ejemplo n.º 1
0
def inputSound():
    # Initialize PyAudio
    pyaud = pyaudio.PyAudio()
    global recording 
    recording = True

    # Open input stream, 16-bit mono at 44100 Hz
    # On my system, device 2 is a USB microphone, your number may differ.
    stream = pyaud.open(
        format = pyaudio.paInt16,
        channels = 1,
        rate = 44100,
        input_device_index = 1,
        input = True)
    times = []
    end = []
    notes = cleanup.notes
    global notesSung
    notesSung = []
    print "*listening*"
    start = time.time()
    # while not cleanup.silentEnd(notesSung):
    while not cleanup.ended(notesSung):
        # Read raw microphone data
        rawsamps = stream.read(1024)
        # print(type(rawsamps), rawsamps)
        # Convert raw data to NumPy array
        samps = numpy.fromstring(rawsamps, dtype=numpy.int16)
        # print(type(samps), samps)
        # Show the volume and pitch
        # analyse.loudness(samps), analyse.musical_detect_pitch(samps)
        freq = analyse.musical_detect_pitch(samps)
        notesSung.append(cleanup.getNote(freq, notes))
        #print cleanup.getNote(freq, notes)
        
    print "*Done*"
    recording = False
    # print notesSung
    cleanup.cleanUp(notesSung)
    # print notesSung
    # print
    cleanup.removeRepeats(notesSung)
    return notesSung
def inputSound():
    # Initialize PyAudio
    pyaud = pyaudio.PyAudio()
    
    # Open input stream, 16-bit mono at 44100 Hz
    # On my system, device 2 is a USB microphone, your number may differ.
    stream = pyaud.open(
        format = pyaudio.paInt16,
        channels = 1,
        rate = 44100,
        input_device_index = 1,
        input = True)
    times = []
    end = []
    notes = cleanup.notes
    notesSung = [] #so that there is an established pause in any beginning
    print "*listening*"
    start = time.time()
    fun = []
    while cleanup.silentEnd(notesSung):
        times.append(time.time()-start)
        fun.append("*")
        # Read raw microphone data
        rawsamps = stream.read(1024)
        # print(type(rawsamps), rawsamps)
        # Convert raw data to NumPy array
        samps = numpy.fromstring(rawsamps, dtype=numpy.int16)
        # print(type(samps), samps)
        # Show the volume and pitch
        # analyse.loudness(samps), analyse.musical_detect_pitch(samps)
        freq = analyse.musical_detect_pitch(samps)
        notesSung.append(cleanup.getNote(freq, notes))
        # print cleanup.getNote(freq, notes)
    print "*Done*"
    print times
    leng = len(notesSung)
    cleanup.cleanUp(notesSung)
    print notesSung
    print len(times), leng, len(notesSung), len(fun)
    print
    print
    cleanup.removeRepeats(notesSung)
    print notesSung
Ejemplo n.º 3
0
def inputSound():
    # Initialize PyAudio
    pyaud = pyaudio.PyAudio()

    # Open input stream, 16-bit mono at 44100 Hz
    # On my system, device 2 is a USB microphone, your number may differ.
    stream = pyaud.open(format=pyaudio.paInt16,
                        channels=1,
                        rate=44100,
                        input_device_index=1,
                        input=True)
    times = []
    end = []
    notes = cleanup.notes
    notesSung = []  #so that there is an established pause in any beginning
    print "*listening*"
    start = time.time()
    fun = []
    while cleanup.silentEnd(notesSung):
        times.append(time.time() - start)
        fun.append("*")
        # Read raw microphone data
        rawsamps = stream.read(1024)
        # print(type(rawsamps), rawsamps)
        # Convert raw data to NumPy array
        samps = numpy.fromstring(rawsamps, dtype=numpy.int16)
        # print(type(samps), samps)
        # Show the volume and pitch
        # analyse.loudness(samps), analyse.musical_detect_pitch(samps)
        freq = analyse.musical_detect_pitch(samps)
        notesSung.append(cleanup.getNote(freq, notes))
        # print cleanup.getNote(freq, notes)
    print "*Done*"
    print times
    leng = len(notesSung)
    cleanup.cleanUp(notesSung)
    print notesSung
    print len(times), leng, len(notesSung), len(fun)
    print
    print
    cleanup.removeRepeats(notesSung)
    print notesSung