import time import librosa import numpy as np import sounddevice as sd def select_device(): devices = sd.query_devices() input_devices = [device for device in devices if device['max_input_channels'] > 0] device_names = [device['name'] for device in input_devices] # Check for "Sound Mixer" for name in input_devices: if "Sound Mixer" in name: return name # Check for "CABLE Output" for name in input_devices: if "CABLE Input" in name: return name # 'CABLE Input (VB-Audio Virtual Cable)' def push_to_mic(data, sr, device_name): # path = "audios/audios/input_audios/5g_Viet.mp3" # data, sr = librosa.load(path) # devices[11] # {'name': 'CABLE Input (VB-Audio Virtual Cable)', # 'index': 11, # 'hostapi': 1, # 'max_input_channels': 0, # 'max_output_channels': 8, # 'default_low_input_latency': 0.0, # 'default_low_output_latency': 0.12, # 'default_high_input_latency': 0.0, # 'default_high_output_latency': 0.24, # 'default_samplerate': 44100.0} # devicename = select_device() #'CABLE Input (VB-Audio Virtual Cable), Windows DirectSound'#'Speakers (Realtek(R) Audio), MME' print(f"Pushing data to {device_name}") # Play the audio through 'headphone' output device sd.play(data, sr, device=device_name) sd.wait() # Wait until file is done playing sd.stop() if __name__ == "__main__": data, sr = librosa.load('audios/audios/output_audios/mic.mp3') device_name = 'CABLE Input (VB-Audio Virtual Cable), Windows DirectSound' push_to_mic(data, sr, device_name)