From: Seoyeon Kim Date: Thu, 14 Nov 2024 09:52:53 +0000 (+0900) Subject: Add to control Speech rate of Accessibility X-Git-Tag: accepted/tizen/unified/20250122.054558~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=83d338be54c04be74ac7198afd46cd544ed45159;p=profile%2Fiot%2Fapps%2Fdotnet%2Fsetting-accessibility.git Add to control Speech rate of Accessibility - There were codes to set Speed before, but it was removed for some reason https://github.sec.samsung.net/m-romaniuk/setting-accessibility-iot/blob/db42e850e96ed8f4fe85b05de9e290a40a2ad617/SettingAccessibilityGadget/AccessibilityMainMenu.cs#L107-L114 - Applied the similar scenario here again Change-Id: I9ea1b532ca7bd2d243218bf78547526901304452 Signed-off-by: Seoyeon Kim --- diff --git a/SettingAccessibility/SettingAccessibility/Interop/Interop.TTS.cs b/SettingAccessibility/SettingAccessibility/Interop/Interop.TTS.cs new file mode 100644 index 0000000..3357cc8 --- /dev/null +++ b/SettingAccessibility/SettingAccessibility/Interop/Interop.TTS.cs @@ -0,0 +1,54 @@ +using System; +using System.Runtime.InteropServices; + +internal static partial class Interop +{ + public static partial class TTS + { + public static partial class Setting + { + [global::System.Runtime.InteropServices.DllImport("libtts_setting.so", EntryPoint = "tts_setting_initialize", CallingConvention = CallingConvention.Cdecl)] + internal static extern int Initialize(); + + [global::System.Runtime.InteropServices.DllImport("libtts_setting.so", EntryPoint = "tts_setting_finalize", CallingConvention = CallingConvention.Cdecl)] + internal static extern int Finalize(); + + [global::System.Runtime.InteropServices.DllImport("libtts_setting.so", EntryPoint = "tts_setting_set_voice", CallingConvention = CallingConvention.Cdecl)] + internal static extern int SetVoice(string language, int voiceType); + + [global::System.Runtime.InteropServices.DllImport("libtts_setting.so", EntryPoint = "tts_setting_set_speed", CallingConvention = CallingConvention.Cdecl)] + internal static extern int SetSpeed(int speed); + } + + internal static string GetErrorName(int error) + { + foreach (var e in Enum.GetValues(typeof(TtsError))) + { + if (error == (int)e) + return e.ToString(); + } + return $"UNKNOWN ({error})"; + } + + private const int ErrorTts = -0x02F10000; + internal enum TtsError + { + None = Tizen.Internals.Errors.ErrorCode.None, /* Successful */ + OutOfMemory = Tizen.Internals.Errors.ErrorCode.OutOfMemory, /* Out of Memory */ + IoError = Tizen.Internals.Errors.ErrorCode.IoError, /* I/O error */ + InvalidParameter = Tizen.Internals.Errors.ErrorCode.InvalidParameter, /* Invalid parameter */ + OutOfNetwork = Tizen.Internals.Errors.ErrorCode.Networkdown, /* Network is down */ + TimedOut = Tizen.Internals.Errors.ErrorCode.TimedOut, /* No answer from the TTS service */ + PermissionDenied = Tizen.Internals.Errors.ErrorCode.PermissionDenied, /* Permission denied */ + NotSupported = Tizen.Internals.Errors.ErrorCode.NotSupported, /* TTS NOT supported */ + InvalidState = ErrorTts | 0x01, /* Invalid state */ + InvalidVoice = ErrorTts | 0x02, /* Invalid language */ + EngineNotFound = ErrorTts | 0x03, /* No available engine */ + OperationFailed = ErrorTts | 0x04, /* Operation failed */ + AudioPolicyBlocked = ErrorTts | 0x05, /* Audio policy blocked */ + NotSupportedFeature = ErrorTts | 0x06, /* Not supported feature of current engine */ + ServiceReset = ErrorTts | 0x07, /* Service reset*/ + ScreenReaderOff = ErrorTts | 0x08 /* Screen reader off */ + }; + } +} diff --git a/SettingAccessibility/SettingAccessibility/Interop/Interop.Vconf.cs b/SettingAccessibility/SettingAccessibility/Interop/Interop.Vconf.cs index 07cf1b2..933f56d 100644 --- a/SettingAccessibility/SettingAccessibility/Interop/Interop.Vconf.cs +++ b/SettingAccessibility/SettingAccessibility/Interop/Interop.Vconf.cs @@ -15,14 +15,16 @@ * */ +using System.Runtime.InteropServices; + internal static partial class Interop { internal static partial class Vconf { - [global::System.Runtime.InteropServices.DllImport("libvconf.so.0", EntryPoint = "vconf_get_bool")] + [global::System.Runtime.InteropServices.DllImport("libvconf.so.0", EntryPoint = "vconf_get_bool", CallingConvention = CallingConvention.Cdecl)] internal static extern int GetVconfBool(string key, out bool value); - [global::System.Runtime.InteropServices.DllImport("libvconf.so.0", EntryPoint = "vconf_set_bool")] + [global::System.Runtime.InteropServices.DllImport("libvconf.so.0", EntryPoint = "vconf_set_bool", CallingConvention = CallingConvention.Cdecl)] internal static extern int SetVconfBool(string key, bool value); } } diff --git a/SettingAccessibility/SettingAccessibility/SettingAccessibility.cs b/SettingAccessibility/SettingAccessibility/SettingAccessibility.cs index f6d9ddc..6728913 100644 --- a/SettingAccessibility/SettingAccessibility/SettingAccessibility.cs +++ b/SettingAccessibility/SettingAccessibility/SettingAccessibility.cs @@ -38,6 +38,8 @@ namespace SettingAccessibility { base.OnCreate(); + Interop.TTS.Setting.Initialize(); + // log debug information var tts = new Tizen.Uix.Tts.TtsClient(); var defaultVoice = tts.DefaultVoice; @@ -112,15 +114,18 @@ namespace SettingAccessibility volume.IsEnabled = false; sections.Add(volume); + // The range of TTS speed is 1 to 15. (Normal is 8) var speechRate = new SpeechRateRow(); speechRate.Slider.MinValue = speedRange.Min; speechRate.Slider.MaxValue = speedRange.Max; - // TODO: use actual value from vconf for CurrentValue, instead of speedRange.Normal speechRate.Slider.CurrentValue = speedRange.Normal; speechRate.Slider.ValueChanged += (s, e) => { - // TODO: save speech rate to vconf - SettingCore.Logger.Verbose($"Speech rate {e.CurrentValue}"); + double ratio = (double)(e.CurrentValue - speechRate.Slider.MinValue) / (speechRate.Slider.MaxValue - speechRate.Slider.MinValue); + int speed = (int)((speedRange.Max - speedRange.Min) * ratio + speedRange.Min); + SettingCore.Logger.Verbose($"Speech rate {speed}"); + + Interop.TTS.Setting.SetSpeed(speed); }; sections.Add(speechRate); @@ -180,5 +185,10 @@ namespace SettingAccessibility return defaultVoice.ToString(); } + protected override void OnDestroy() + { + Interop.TTS.Setting.Finalize(); + base.OnDestroy(); + } } }