bastibe/SoundCard

choosing device

Closed this issue · 1 comments

  1. 'Soundcard' allows to choose input device for recording and output device for playing sound. But it can't choose device to "listen" sound.
    I installed 'Virtual Audio Cable' which creates 'Virtual input' and 'Virtual output' which allows to record sound from system directly. It works when I choose them using 'sc.default_speaker()[ i ]' and 'sc.all_microphones()[ i ]' but I have to choose them in windows properties anyway. How can I choose sound devices from Python only?

  2. 'Soundcard' has noises during playing sound comparing to 'PyAudio'. I can give both two examples - 'Soundcard' and 'PyAudio' codes.
    Soundcard:

    import soundcard as sc
    speakers = sc.all_speakers()
    default_speaker = sc.default_speaker()
    mics = sc.all_microphones()
    default_mic = sc.default_microphone()
    with default_mic.recorder(samplerate=48000) as mic,
    default_speaker.player(samplerate=48000) as sp:
    while True:
    data = mic.record(numframes=1024)
    sp.play(data)

PyAudio:

import pyaudio
import numpy as np
CHUNK = 1024
WIDTH = 2
p = pyaudio.PyAudio()
stream = p.open(format=p.get_format_from_width(WIDTH),
    channels = 1,
    rate = 44100,
    input = True,
    output = True,
    frames_per_buffer = CHUNK,
    input_device_index = 1)	
data=[]	
while True:
    data.append(stream.read(CHUNK))
    stream.write(data.pop(0), CHUNK)
    data=[]
  1. Why 'mic.record(numframes=1024)' has (1024, 2) shape? Why does it have two rows and not one?

Please read the documentation before asking questions.

  1. use soundcard.get_speaker(...) and soundcard.get_microphone(...) to select a speaker or microphone. If you pass include_loopback=True to get_microphone, you can listen in on your speakers (not available on all operating systems).
  2. Set a common block size, and use compatible clocks. Synchronous playback and recording is always difficult, especially if different sound cards are used. Sample rates differ, hardware clocks drift... use buffering if you want to avoid such problems. PyAudio uses buffering internally, and therefore has higher latency.
  3. Because your microphone has two channels.

Furthermore, this is not a support forum, but a place for reporting issues and discussing development.