Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Actually use the advertised audio device and sample rate with the audio test. #265

Merged
merged 3 commits into from
Jan 25, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions mycroft/util/audio_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from mycroft.listener.mic import MutableMicrophone
from ovos_config.config import Configuration
from mycroft.util.audio_utils import play_wav
from mycroft.util.audio_utils import play_wav, find_input_device
from mycroft.util.log import LOG
import logging
from mycroft.util.file_utils import get_temp_path
Expand Down Expand Up @@ -61,8 +61,8 @@ def mute_output():
os.close(fd)


def record(filename, duration):
mic = MutableMicrophone()
def record(filename, duration, device_index=None):
mic = MutableMicrophone(device_index)
recognizer = Recognizer()
with mic as source:
audio = recognizer.record(source, duration=duration)
Expand Down Expand Up @@ -103,14 +103,21 @@ def main():
print()

config = Configuration()
device_index = None
if "device_name" in config["listener"]:
dev = config["listener"]["device_name"]
device_index = find_input_device(dev)
if not device_index:
raise ValueError("Device with name {} not found, check your configuration".format(dev))
JarbasAl marked this conversation as resolved.
Show resolved Hide resolved
dev += " (index {})".format(device_index)
elif "device_index" in config["listener"]:
dev = "Device at index {}".format(config["listener"]["device_index"])
device_index = int(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(" Input device: {} @ Sample rate: {} Hz".format(dev, samplerate))
print(" Playback commandline: {}".format(play_cmd))
Expand All @@ -121,9 +128,9 @@ def main():

if not args.verbose:
with mute_output():
record(args.filename, args.duration)
record(args.filename, args.duration, device_index=device_index)
else:
record(args.filename, args.duration)
record(args.filename, args.duration, device_index=device_index)

print(" ===========================================================")
print(" == DONE RECORDING, PLAYING BACK... ==")
Expand Down