Initial pass at getting all the scripts and menus working with the new everything in home setup. Also unify speech settings. Not sure why I thought separate speech settings for all menus was a good idea lol.
This commit is contained in:
@@ -10,6 +10,37 @@ import curses
|
||||
import speechd
|
||||
import subprocess
|
||||
import configparser
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
SPEECHD_CONFIG = Path.home() / ".local" / "etc" / "speech-dispatcher" / "speechd.conf"
|
||||
|
||||
|
||||
def update_default_module_content(content, module):
|
||||
"""Return speechd.conf content with DefaultModule set to module."""
|
||||
if re.search(r'^\s*DefaultModule\s+', content, re.MULTILINE):
|
||||
return re.sub(
|
||||
r'^(\s*)DefaultModule\s+\S+',
|
||||
f'\\1DefaultModule {module}',
|
||||
content,
|
||||
flags=re.MULTILINE,
|
||||
)
|
||||
|
||||
return re.sub(
|
||||
r'^(\s*)#\s*DefaultModule\s+\S*',
|
||||
f'\\1DefaultModule {module}',
|
||||
content,
|
||||
flags=re.MULTILINE,
|
||||
)
|
||||
|
||||
|
||||
def set_default_module_in_config(configPath, module):
|
||||
"""Update DefaultModule without replacing a symlink at configPath."""
|
||||
configPath = Path(configPath)
|
||||
content = configPath.read_text()
|
||||
configPath.write_text(update_default_module_content(content, module))
|
||||
return True
|
||||
|
||||
class VoiceSelectionMenu:
|
||||
def __init__(self, title="Speech Dispatcher Voice Selection"):
|
||||
@@ -146,42 +177,12 @@ class VoiceSelectionMenu:
|
||||
try:
|
||||
# Clean up before executing system commands
|
||||
self.cleanup(full_cleanup=False)
|
||||
|
||||
# Read the current config file
|
||||
import re
|
||||
with open('/etc/speech-dispatcher/speechd.conf', 'r') as f:
|
||||
content = f.read()
|
||||
|
||||
# Check if DefaultModule is already uncommented
|
||||
if re.search(r'^\s*DefaultModule\s+', content, re.MULTILINE):
|
||||
# Replace existing DefaultModule line
|
||||
new_content = re.sub(
|
||||
r'^(\s*)DefaultModule\s+\S+',
|
||||
f'\\1DefaultModule {module}',
|
||||
content,
|
||||
flags=re.MULTILINE
|
||||
)
|
||||
else:
|
||||
# Uncomment and set DefaultModule line
|
||||
new_content = re.sub(
|
||||
r'^(\s*)#\s*DefaultModule\s+\S*',
|
||||
f'\\1DefaultModule {module}',
|
||||
content,
|
||||
flags=re.MULTILINE
|
||||
)
|
||||
|
||||
# Write to a temporary file
|
||||
temp_file = "/tmp/speechd.conf.new"
|
||||
with open(temp_file, 'w') as f:
|
||||
f.write(new_content)
|
||||
|
||||
# Use sudo to move the file to the correct location
|
||||
subprocess.run(f"sudo mv {temp_file} /etc/speech-dispatcher/speechd.conf", shell=True, check=True)
|
||||
set_default_module_in_config(SPEECHD_CONFIG, module)
|
||||
|
||||
# Restart speech-dispatcher more thoroughly
|
||||
subprocess.run("sudo systemctl restart speech-dispatcher", shell=True, check=False)
|
||||
subprocess.run(["systemctl", "--user", "restart", "speech-dispatcher.socket"], check=False)
|
||||
# Also kill any remaining processes
|
||||
subprocess.run("sudo killall speech-dispatcher", shell=True, check=False)
|
||||
subprocess.run(["killall", "speech-dispatcher"], check=False)
|
||||
|
||||
# Re-initialize speech after changes
|
||||
time.sleep(2) # Give more time for the service to restart
|
||||
|
||||
Reference in New Issue
Block a user