Add device-list
This commit is contained in:
parent
a91ab70f57
commit
0b8763b30e
15
README.md
15
README.md
|
@ -14,6 +14,13 @@ Audio I/O for real-time applications, like VoIP.
|
||||||
- `aspew-in.py` takes a microphone as an input, and outputs it to pipe.
|
- `aspew-in.py` takes a microphone as an input, and outputs it to pipe.
|
||||||
- `aspew-out.py` takes input from a pipe, and outputs it to a speaker.
|
- `aspew-out.py` takes input from a pipe, and outputs it to a speaker.
|
||||||
|
|
||||||
|
## Flags
|
||||||
|
Flags formatted as `-s` or `--long`.
|
||||||
|
|
||||||
|
### in & out:
|
||||||
|
- `-l`: List devices as JSON
|
||||||
|
- `-h`: Use human-readable format
|
||||||
|
|
||||||
## Arguments
|
## Arguments
|
||||||
Arguments are pairs of key=value.
|
Arguments are pairs of key=value.
|
||||||
|
|
||||||
|
@ -32,4 +39,10 @@ Arguments are pairs of key=value.
|
||||||
Listen to your default microphone at default settings.
|
Listen to your default microphone at default settings.
|
||||||
|
|
||||||
- `./aspew-in.py format=paInt16 bitrate=48000 channels=2 | ./aspew-out.py format=paInt16 bitrate=48000 channels=2`
|
- `./aspew-in.py format=paInt16 bitrate=48000 channels=2 | ./aspew-out.py format=paInt16 bitrate=48000 channels=2`
|
||||||
Listen to your default microphone at 16-bit, 48000Hz, stereo.
|
Listen to your default microphone at 16-bit, 48000Hz, stereo.
|
||||||
|
|
||||||
|
- `./aspew-in.py -lh`
|
||||||
|
List your input devices.
|
||||||
|
|
||||||
|
- `./aspew-out.py -lh`
|
||||||
|
List your output devices.
|
47
aspew-in.py
47
aspew-in.py
|
@ -5,6 +5,25 @@ import time
|
||||||
import pyaudio
|
import pyaudio
|
||||||
unbufferedStdout = os.fdopen(sys.stdout.fileno(),"wb",0) # Make unbuffered stdout
|
unbufferedStdout = os.fdopen(sys.stdout.fileno(),"wb",0) # Make unbuffered stdout
|
||||||
|
|
||||||
|
def parseFlags():
|
||||||
|
rtn = []
|
||||||
|
for arg in sys.argv[1:]:
|
||||||
|
arg = arg.replace(" ","")
|
||||||
|
arg = arg.replace("\t","")
|
||||||
|
arg = arg.replace("\r","")
|
||||||
|
arg = arg.replace("\n","")
|
||||||
|
if arg[0] != "-": continue
|
||||||
|
if arg == "-": continue
|
||||||
|
|
||||||
|
if arg[:2] == "--":
|
||||||
|
rtn.append(arg[2:])
|
||||||
|
continue
|
||||||
|
|
||||||
|
for i in arg[1:]:
|
||||||
|
rtn.append(i)
|
||||||
|
|
||||||
|
return rtn
|
||||||
|
|
||||||
def parseSettings():
|
def parseSettings():
|
||||||
rtn = {}
|
rtn = {}
|
||||||
for arg in sys.argv[1:]:
|
for arg in sys.argv[1:]:
|
||||||
|
@ -25,6 +44,34 @@ def streamHandler(in_data, frame_count, time_info, status):
|
||||||
unbufferedStdout.write(in_data)
|
unbufferedStdout.write(in_data)
|
||||||
return (in_data, pyaudio.paContinue)
|
return (in_data, pyaudio.paContinue)
|
||||||
|
|
||||||
|
flags = parseFlags()
|
||||||
|
|
||||||
|
if "l" in flags:
|
||||||
|
devices = {}
|
||||||
|
audio = pyaudio.PyAudio()
|
||||||
|
defaultDevice = audio.get_default_host_api_info()["defaultInputDevice"]
|
||||||
|
devices["default"] = defaultDevice
|
||||||
|
for i in range(0, audio.get_device_count()):
|
||||||
|
info = audio.get_device_info_by_index(i)
|
||||||
|
if info["maxInputChannels"] == 0: continue
|
||||||
|
|
||||||
|
devices[i] = {
|
||||||
|
"name": info["name"],
|
||||||
|
"api": audio.get_host_api_info_by_index(info["hostApi"])["name"]
|
||||||
|
}
|
||||||
|
|
||||||
|
if not "h" in flags:
|
||||||
|
import json
|
||||||
|
print(json.dumps(devices))
|
||||||
|
else:
|
||||||
|
print("\nAvailable input devices:")
|
||||||
|
for i in devices:
|
||||||
|
if i == "default": continue
|
||||||
|
st = str(i)+ ": " +devices[i]["name"]+ " [" +devices[i]["api"]+ "]"
|
||||||
|
if i == defaultDevice: st = st + " *"
|
||||||
|
print(st)
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
settings = parseSettings()
|
settings = parseSettings()
|
||||||
audioFormat = getSetting(settings,str,["f","format"],"paUInt8")
|
audioFormat = getSetting(settings,str,["f","format"],"paUInt8")
|
||||||
audioChannels = getSetting(settings,int,["c","channel","channels"],1)
|
audioChannels = getSetting(settings,int,["c","channel","channels"],1)
|
||||||
|
|
47
aspew-out.py
47
aspew-out.py
|
@ -58,6 +58,25 @@ def streamHandler(in_data, frame_count, time_info, status):
|
||||||
data += getAudioFrame()
|
data += getAudioFrame()
|
||||||
return (data, pyaudio.paContinue)
|
return (data, pyaudio.paContinue)
|
||||||
|
|
||||||
|
def parseFlags():
|
||||||
|
rtn = []
|
||||||
|
for arg in sys.argv[1:]:
|
||||||
|
arg = arg.replace(" ","")
|
||||||
|
arg = arg.replace("\t","")
|
||||||
|
arg = arg.replace("\r","")
|
||||||
|
arg = arg.replace("\n","")
|
||||||
|
if arg[0] != "-": continue
|
||||||
|
if arg == "-": continue
|
||||||
|
|
||||||
|
if arg[:2] == "--":
|
||||||
|
rtn.append(arg[2:])
|
||||||
|
continue
|
||||||
|
|
||||||
|
for i in arg[1:]:
|
||||||
|
rtn.append(i)
|
||||||
|
|
||||||
|
return rtn
|
||||||
|
|
||||||
def parseSettings():
|
def parseSettings():
|
||||||
rtn = {}
|
rtn = {}
|
||||||
for arg in sys.argv[1:]:
|
for arg in sys.argv[1:]:
|
||||||
|
@ -74,6 +93,34 @@ def getSetting(lst,tp,keys,default = None):
|
||||||
return tp(lst[key])
|
return tp(lst[key])
|
||||||
return default
|
return default
|
||||||
|
|
||||||
|
flags = parseFlags()
|
||||||
|
|
||||||
|
if "l" in flags:
|
||||||
|
devices = {}
|
||||||
|
audio = pyaudio.PyAudio()
|
||||||
|
defaultDevice = audio.get_default_host_api_info()["defaultOutputDevice"]
|
||||||
|
devices["default"] = defaultDevice
|
||||||
|
for i in range(0, audio.get_device_count()):
|
||||||
|
info = audio.get_device_info_by_index(i)
|
||||||
|
if info["maxOutputChannels"] == 0: continue
|
||||||
|
|
||||||
|
devices[i] = {
|
||||||
|
"name": info["name"],
|
||||||
|
"api": audio.get_host_api_info_by_index(info["hostApi"])["name"]
|
||||||
|
}
|
||||||
|
|
||||||
|
if not "h" in flags:
|
||||||
|
import json
|
||||||
|
print(json.dumps(devices))
|
||||||
|
else:
|
||||||
|
print("\nAvailable output devices:")
|
||||||
|
for i in devices:
|
||||||
|
if i == "default": continue
|
||||||
|
st = str(i)+ ": " +devices[i]["name"]+ " [" +devices[i]["api"]+ "]"
|
||||||
|
if i == defaultDevice: st = st + " *"
|
||||||
|
print(st)
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
settings = parseSettings()
|
settings = parseSettings()
|
||||||
audioFormat = getSetting(settings,str,["f","format"],"paUInt8")
|
audioFormat = getSetting(settings,str,["f","format"],"paUInt8")
|
||||||
audioChannels = getSetting(settings,int,["c","channel","channels"],1)
|
audioChannels = getSetting(settings,int,["c","channel","channels"],1)
|
||||||
|
|
Loading…
Reference in New Issue