From 569ed6c0cc440572b37a06200b6706badcdf8e45 Mon Sep 17 00:00:00 2001 From: Tursiae Date: Tue, 11 Feb 2025 00:23:35 +0000 Subject: TTS: Implement and wire up a TTS toggle in Display Settings (#251) This change introduces the ability to enable or disable the spoken interface/TTS from the on-device settings, either via the UI or the Lua console. This closes out the implementation of issue #245. The TTS setting is only visible in Display settings if voice samples are present in `/.tangara-tts/` on the SD card. Playback of new TTS voice samples is inhibited when TTS is disabled. By default, the setting is enabled, as the device will only play back TTS voices if samples are present on disk. If you need samples to test TTS on your device, feel free to grab the voice samples I have at https://codeberg.org/tursiae/tangara-tts-samples. There's about 80-85% coverage of the UI, with the remainder to be added soonish. Reviewed-on: https://codeberg.org/cool-tech-zone/tangara-fw/pulls/251 Co-authored-by: Tursiae Co-committed-by: Tursiae --- lua/settings.lua | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'lua/settings.lua') diff --git a/lua/settings.lua b/lua/settings.lua index 0ae4e73d..0238a876 100644 --- a/lua/settings.lua +++ b/lua/settings.lua @@ -320,6 +320,43 @@ settings.DisplaySettings = SettingsScreen:new { brightness_pct:set { text = tostring(b) .. "%" } end) } + + -- Only show the TTS option if there are voice samples on disk. + local tts_iter = filesystem.iterator("/.tangara-tts/") + for _ in tts_iter do + local text_to_speech_container = self.content:Object { + flex = { + flex_direction = "row", + justify_content = "flex-start", + align_items = "center", + align_content = "flex-start", + }, + w = lvgl.PCT(100), + h = lvgl.SIZE_CONTENT, + pad_bottom = 4, + } + text_to_speech_container:add_style(styles.list_item) + text_to_speech_container:Label { text = "Spoken Interface", flex_grow = 1 } + local text_to_speech_sw = text_to_speech_container:Switch {} + local tts_desc = widgets.Description(text_to_speech_sw, "Spoken interface") + + text_to_speech_sw:onevent(lvgl.EVENT.VALUE_CHANGED, function() + display.text_to_speech:set(text_to_speech_sw:enabled()) + end) + + self.bindings = self.bindings + { + display.text_to_speech:bind(function(en) + if en then + text_to_speech_sw:add_state(lvgl.STATE.CHECKED) + else + text_to_speech_sw:clear_state(lvgl.STATE.CHECKED) + end + end), + } + + break + end + end } -- cgit v1.2.3