Location>code7788 >text

python audio processing (1) - resampling, pitch extraction

Popularity:641 ℃/2024-08-01 16:07:21
import torchaudio import as Tf import as plt import librosa def get_pitch_by_torch(): file_path = input("file path:") y, sr = (file_path) """specimen: >>> waveform, sample_rate = ("", normalize=True) >>> transform = (sample_rate, 4) >>> waveform_shift = transform(waveform) # (channel, time) """ pitch_tf = (sample_rate=sr, n_steps=0) feature = pitch_tf(y) # Mapping of fundamental frequency characteristics (figsize=(16, 5)) (feature[0][5000:10000].numpy(), label='Pitch') ('Frame') ('Frequency (Hz)') ('Pitch Estimation') () () def get_pitch_by_librosa(): ​ file_path = input("Please enter the audio file path:") y, sr = (file_path) """(y,sr=sr,fmin=librosa.note_to_hz('C2'),fmax=librosa.note_to_hz('C7'))""" # Extraction of fundamental frequency features using pyin f0, voiced_flag, voiced_probs = (y, sr=sr, fmin=librosa.note_to_hz('C2'), fmax=librosa.note_to_hz('C7')) ​ # Plotting of fundamental frequency characteristics, negligible (figsize=(14, 5)) (y, sr=sr, alpha=0.5) (librosa.times_like(f0), f0, label='f0 (fundamental frequency)', color='r') ('Time (s)') ('Frequency (Hz)') ('Pitch (fundamental frequency) Estimation') () () if __name__ == '__main__': # get_pitch_by_torch() # get_pitch_by_librosa()