【发布时间】:2021-02-18 11:56:29
【问题描述】:
我目前正在使用多个库和 VB 虚拟音频电缆将麦克风输入传输到虚拟麦克风。我能够成功地做到这一点,但虚拟麦克风中的音频非常失真。有什么帮助吗?
代码:
import sounddevice as sd
import numpy
from pygame import mixer
import pygame
from pygame._sdl2 import get_num_audio_devices, get_audio_device_name
import random
from scipy.io.wavfile import write
mixer.init() #Initialize the mixer, this will allow the next command to work
devices = [get_audio_device_name(x, 0).decode() for x in range(get_num_audio_devices(0))] #Returns playback devices
print(devices)
mixer.quit()
pygame.mixer.init(devicename='CABLE Input (VB-Audio Virtual Cable)', frequency=44100, size=32, channels=21, buffer=4)
def callback(indata, outdata, frames, time, status):
if status:
print(status)
outdata[:] = indata
number = random.randint(1,9999999999999999)
filename = f'output/output{str(number)}.wav'
write(filename, 44100, outdata) # Save as uncompressed WAV file
sound = pygame.mixer.Sound(filename) #Load the wav
sound.play() #Play it
# For device, first number is input and second number is output
with sd.Stream(device=(3, 8), samplerate=44100, blocksize=0, latency=00.1,
channels=2, callback=callback) as s:
print('Recording')
input()
感谢任何帮助。
【问题讨论】: