Add sound volume multiplier

This commit is contained in:
Michael Hansen
2024-01-16 17:06:30 -06:00
parent a44dc28cdf
commit f6fcf74c3a
4 changed files with 40 additions and 12 deletions
+13 -4
View File
@@ -35,7 +35,12 @@ def configure_microphone(settings: Settings) -> None:
_LOGGER.warning("Failed to record from microphone %s", device) _LOGGER.warning("Failed to record from microphone %s", device)
continue continue
_LOGGER.debug("Microphone %s got RMS %s (min: %s)", device, device_rms, RECORD_RMS_MIN) _LOGGER.debug(
"Microphone %s got RMS %s (min: %s)",
device,
device_rms,
RECORD_RMS_MIN,
)
if device_rms < RECORD_RMS_MIN: if device_rms < RECORD_RMS_MIN:
continue continue
@@ -48,8 +53,10 @@ def configure_microphone(settings: Settings) -> None:
settings.mic.device = best_device settings.mic.device = best_device
settings.save() settings.save()
else: else:
msgbox("Audio was not detected from any microphone.\n" msgbox(
"If a satellite is currently running, you may need to stop it.") "Audio was not detected from any microphone.\n"
"If a satellite is currently running, you may need to stop it."
)
elif choice == "list": elif choice == "list":
# arecord -L # arecord -L
microphone_device = radiolist( microphone_device = radiolist(
@@ -120,7 +127,9 @@ def _record_proc(device: str) -> Optional[float]:
) )
audio, stderr = proc.communicate() audio, stderr = proc.communicate()
if proc.returncode != 0: if proc.returncode != 0:
_LOGGER.error("Error recording from device %s: %s", device, stderr.decode("utf-8")) _LOGGER.error(
"Error recording from device %s: %s", device, stderr.decode("utf-8")
)
return None return None
# 16-bit mono # 16-bit mono
+4 -6
View File
@@ -17,7 +17,7 @@ from .whiptail import error, msgbox, run_with_gauge
def stop_services(password: str) -> None: def stop_services(password: str) -> None:
stop_commands = [] stop_commands = []
for service in ("satellite", "openwakeword", "porcupine1", "snowboy"): for service in ("satellite", "wakeword", "event"):
service_filename = f"wyoming-{service}.service" service_filename = f"wyoming-{service}.service"
service_path = Path("/etc/systemd/system") / service_filename service_path = Path("/etc/systemd/system") / service_filename
if not service_path.exists(): if not service_path.exists():
@@ -83,10 +83,8 @@ def generate_services(settings: Settings) -> None:
# Local wake word detection # Local wake word detection
assert settings.wake.system is not None, "Wake word system not set" assert settings.wake.system is not None, "Wake word system not set"
wake_word_service = ( wake_word_service = "wyoming-wakeword"
"wyoming-" + WakeWordSystem(settings.wake.system).value.lower() wake_word_dir = LOCAL_DIR / WakeWordSystem(settings.wake.system).value.lower()
)
wake_word_dir = LOCAL_DIR / wake_word_service
wake_word_command = [ wake_word_command = [
str(wake_word_dir / "script" / "run"), str(wake_word_dir / "script" / "run"),
"--uri", "--uri",
@@ -165,7 +163,7 @@ def generate_services(settings: Settings) -> None:
SERVICES_DIR / f"{event_service}.service", "w", encoding="utf-8" SERVICES_DIR / f"{event_service}.service", "w", encoding="utf-8"
) as service_file: ) as service_file:
print("[Unit]", file=service_file) print("[Unit]", file=service_file)
print(f"Description=Event service", file=service_file) print("Description=Event service", file=service_file)
print("", file=service_file) print("", file=service_file)
print("[Service]", file=service_file) print("[Service]", file=service_file)
print("Type=simple", file=service_file) print("Type=simple", file=service_file)
+21
View File
@@ -53,6 +53,26 @@ def configure_speakers(settings: Settings) -> None:
if feedback_sounds is not None: if feedback_sounds is not None:
settings.snd.feedback_sounds = feedback_sounds settings.snd.feedback_sounds = feedback_sounds
settings.save() settings.save()
elif choice == "multiplier":
while True:
volume_multiplier = inputbox(
"Volume Multipler (1 = default)", settings.snd.volume_multiplier
)
if volume_multiplier is None:
break
try:
volume_multiplier_float = float(volume_multiplier)
except ValueError:
msgbox("Invalid value")
continue
if volume_multiplier_float > 0:
settings.snd.volume_multiplier = volume_multiplier_float
settings.save()
break
msgbox("Must be > 0")
else: else:
break break
@@ -66,6 +86,7 @@ def speakers_menu(last_choice: Optional[str]) -> Optional[str]:
("list", "Select From List"), ("list", "Select From List"),
("manual", "Enter Manually"), ("manual", "Enter Manually"),
("disable", "Disable Sound"), ("disable", "Disable Sound"),
("multipler", "Volume Multipler"),
("feedback", "Toggle Feedback Sounds"), ("feedback", "Toggle Feedback Sounds"),
], ],
selected_item=last_choice, selected_item=last_choice,
+2 -2
View File
@@ -159,7 +159,7 @@ class SatelliteBase:
try: try:
await async_write_event(event, self._writer) await async_write_event(event, self._writer)
except Exception as err: except Exception as err:
self.clear_server() await self.clear_server()
if isinstance(err, ConnectionResetError): if isinstance(err, ConnectionResetError):
_LOGGER.warning("Server disconnected unexpectedly") _LOGGER.warning("Server disconnected unexpectedly")
@@ -558,7 +558,7 @@ class SatelliteBase:
try: try:
if mute_microphone: if mute_microphone:
with wave.open(wav_path, "rb") as wav_file: with wave.open(str(wav_path), "rb") as wav_file:
seconds_to_mute = wav_file.getnframes() / wav_file.getframerate() seconds_to_mute = wav_file.getnframes() / wav_file.getframerate()
seconds_to_mute += self.settings.mic.seconds_to_mute_after_awake_wav seconds_to_mute += self.settings.mic.seconds_to_mute_after_awake_wav