Fix typo and add --list option

The -l / --list option will now display the name and index of all available input devices.
pull/1971/head
Steve Penrod 2019-01-31 01:11:58 -06:00 committed by Åke Forslund
parent 8693b71c0e
commit df4f6ca6dd
1 changed files with 18 additions and 2 deletions

View File

@ -14,6 +14,7 @@
#
import argparse
import os
import pyaudio
from contextlib import contextmanager
from speech_recognition import Recognizer
@ -79,18 +80,33 @@ def main():
parser.add_argument(
'-v', '--verbose', dest='verbose', action='store_true', default=False,
help="Add extra output regarding the recording")
parser.add_argument(
'-l', '--list', dest='show_devices', action='store_true',
default=False, help="List all availabile input devices")
args = parser.parse_args()
if args.show_devices:
print(" Initializing... ")
pa = pyaudio.PyAudio()
print(" ====================== Audio Devices ======================")
print(" Index Device Name")
for device_index in range(pa.get_device_count()):
dev = pa.get_device_info_by_index(device_index)
if dev['maxInputChannels'] > 0:
print(' {}: {}'.format(device_index, dev['name']))
print()
config = Configuration.get()
if "device_name" in config["listener"]:
dev = config["listener"]["device_name"]
elif "device_index" in config["listenter"]:
elif "device_index" in config["listener"]:
dev = "Device at index {}".format(config["listener"]["device_index"])
else:
dev = "Default device"
samplerate = config["listener"]["sample_rate"]
play_cmd = config["play_wav_cmdline"].replace("%1", "WAV_FILE")
print(" ============================= Info ==============================")
print(" ========================== Info ===========================")
print(" Input device: {} @ Sample rate: {} Hz".format(dev, samplerate))
print(" Playback commandline: {}".format(play_cmd))
print()