You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to know the pitch by frame by running the mp3 or wav file
When the pitch value is output, 0 is continuously displayed.
where is the problem?
I want to (Ex, C1, F2)
importaubioimportnumpyasnpimportpyaudioimporttimeimportargparseimportqueueimportwaveimportmusic21# yes! new favorite library# parser = argparse.ArgumentParser()# parser.add_argument("-input", required=False, type=int, help="Audio Input Device")# args = parser.parse_args()## if not args.input:# print("No input device specified. Printing list of input devices now: ")# p = pyaudio.PyAudio()# for i in range(p.get_device_count()):# print("Device number (%i): %s" % (i, p.get_device_info_by_index(i).get('name')))# print("Run this program with -input 1, or the number of the input you'd like to use.")# exit()CHUNK=1024wf=wave.open("temp.wav", 'rb')
# PyAudio object.p=pyaudio.PyAudio()
# Open stream.stream=p.open(format=p.get_format_from_width(wf.getsampwidth()),
channels=wf.getnchannels(),
rate=wf.getframerate(),
output=True)
# stream = p.open(format=pyaudio.paFloat32,# channels=1, rate=44100, input=True,# input_device_index=args.input, frames_per_buffer=4096)time.sleep(1)
data=wf.readframes(CHUNK)
# Aubio's pitch detection.pDetection=aubio.pitch("default", 2048, 2048//2, 44100)
# Set unit.pDetection.set_unit("Hz")
pDetection.set_silence(-40)
q=queue.Queue()
defget_current_note(volume_thresh=0.01, printOut=False):
globaldata"""Returns the Note Currently Played on the q object when audio is present Keyword arguments: volume_thresh -- the volume threshold for input. defaults to 0.01 printOut -- whether or not to print to the terminal. defaults to False """current_pitch=music21.pitch.Pitch()
whileTrue:
stream.write(data)
data=wf.readframes(CHUNK)
samples=np.fromstring(data, dtype=aubio.float_type)
pitch=pDetection(samples)[0]
print(pitch)
# Compute the energy (volume) of the# current frame.volume=np.sum(samples**2) /len(samples) *100# print(volume)ifpitch>volume_thresh: # adjust with your mic!current_pitch.frequency=pitchelse:
continueifprintOut:
print(current_pitch)
else:
current=current_pitch.nameWithOctaveq.put({'Note': current, 'Cents': current_pitch.microtone.cents})
if__name__=='__main__':
get_current_note(volume_thresh=0.001, printOut=True)
The text was updated successfully, but these errors were encountered:
I want to know the pitch by frame by running the mp3 or wav file
When the pitch value is output, 0 is continuously displayed.
where is the problem?
I want to (Ex, C1, F2)
The text was updated successfully, but these errors were encountered: