def process_audio(rmvpe, audio_path, output_path, device, hop_length, threshold):
    """Process an audio file in 10-second chunks and save the results."""
    # Load the audio file
    audio, sr = librosa.load(str(audio_path), sr=None)
    chunk_size = 10 * sr
    # pad to make the audio length to be multiple of hop_length
    audio = np.pad(audio, (0, chunk_size - len(audio) % chunk_size), mode='constant')
    
    # Calculate chunk size in samples (10 seconds * sample rate)
    total_chunks = int(np.round(len(audio) / chunk_size))
    
    # Initialize arrays to store results
    all_f0 = []
    total_infer_time = 0
    
    # Process each chunk
    for i in tqdm(range(total_chunks)):
        start_idx = i * chunk_size
        end_idx = min((i + 1) * chunk_size, len(audio))
        chunk = audio[start_idx:end_idx]
        
        # Process the chunk
        t = time.time()
        f0_chunk = rmvpe.infer_from_audio(chunk, sr, device=device, thred=threshold, use_viterbi=True)
        chunk_infer_time = time.time() - t
        total_infer_time += chunk_infer_time
        
        # Append results
        all_f0.extend(f0_chunk)
    
    # Create output directory if it doesn't exist
    output_path.parent.mkdir(parents=True, exist_ok=True)

    # remove all 0 in the f0
    all_f0 = np.array(all_f0)
    all_f0 = all_f0[all_f0 != 0]

    # convert all_f0 to a list
    all_f0 = all_f0.tolist()
    
    # Save the results
    with open(output_path, 'w') as f:
        for f0 in all_f0:
            f.write(f'{f0:.2f}\n')
    
    return total_infer_time, len(audio) / sr  # Return total inference time and audio duration
Process an audio file in 10-second chunks and save the results.
evals/pitch_range/main.py