Idea: Read the user's microphone and in real time (possible delay up to 500ms) change the pitch of the audio and play it to the output device (Virtual Audio Cable).
from librosa.effects import pitch_shift
...
def pitch_shift_callback(in_data, frame_count, time_info, status):
pitch_value = 6
audio_data = np.frombuffer(in_data, dtype=np.float32)
shifted_audio_data = pitch_shift(audio_data, sr=44100, n_steps=pitch_value)
out_data = shifted_audio_data.tobytes()
return (out_data, pyaudio.paContinue)
...
p = pyaudio.PyAudio()
stream = p.open(format=pyaudio.paFloat32, channels=1, rate=44100,
input_device_index=SETTINGS["INPUT_DEVICE"],
output_device_index=SETTINGS["OUTPUT_DEVICE"],
input=True, output=True,
stream_callback=pitch_shift_callback,
frames_per_buffer=2048)
I have a fairly powerful computer, but when processing, I get a choppy effect between chunks.
I tried increasing and decreasing the size of the chunks, but it does not help.
I also researched why this happens. If you leave the raw audio (don't resample it) and just set time.sleep(0.05)
, then this choppy effect will also appear.
def pitch_shift_callback(in_data, frame_count, time_info, status):
time.sleep(0.01)
return (in_data, pyaudio.paContinue)
Does anyone know how this can be fixed? Help please.