Yêu cầu thg 12 22, 2022 3:36 SA 56 0 0
  • 56 0 0
+1

Thay đổi input/output khi record bằng sounddevice trong python?

Chia sẻ
  • 56 0 0

Mình đang dùng thư viện sounddevice trong python để record, nhưng độ trễ lúc bắt đầu record là khoảng 0.01s, khi ghép audio lại vẫn bị mất tiếng. Show các device như trên ảnh ấy thì có 3 device cuối có latency thấp, mà mình k biết dùng như nào. Lệnh sd.default.device thì đổi được device nhưng khi chạy lại bị lỗi. Mn biết cách nào sd được các device này.

import numpy as np
import sounddevice as sd
from scipy.io.wavfile import write
import soundfile as sf
import IPython.display as ipd
from queue import Queue
from IPython.display import Audio 

seconds = 5
fs = 44100
recordings = Queue()
sd.default.latency = 'low'
# sd.default.device=5,4
print(sd.query_devices())
def rec_5s():
    print('Starting...')
    for _ in range (3):
        myrecording = sd.rec(int(seconds * fs), 
                        samplerate=fs, channels=1, dtype = np.int16)                                               
        sd.wait()
        recordings.put(myrecording)
        
rec_5s()
rec1 = recordings.get()
rec2 = recordings.get()
rec3 = recordings.get()
rec = np.concatenate((rec1,rec2,rec3))
write('rec_5s_2.wav', fs, rec)

Viblo
Hãy đăng ký một tài khoản Viblo để nhận được nhiều bài viết thú vị hơn.
Đăng kí