Add to control Speech rate of Accessibility 01/316901/4
authorSeoyeon Kim <seoyeon2.kim@samsung.com>
Thu, 14 Nov 2024 09:52:53 +0000 (18:52 +0900)
committerSeoyeon Kim <seoyeon2.kim@samsung.com>
Tue, 24 Dec 2024 05:58:08 +0000 (14:58 +0900)
- 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 <seoyeon2.kim@samsung.com>
SettingAccessibility/SettingAccessibility/Interop/Interop.TTS.cs [new file with mode: 0644]
SettingAccessibility/SettingAccessibility/Interop/Interop.Vconf.cs
SettingAccessibility/SettingAccessibility/SettingAccessibility.cs

diff --git a/SettingAccessibility/SettingAccessibility/Interop/Interop.TTS.cs b/SettingAccessibility/SettingAccessibility/Interop/Interop.TTS.cs
new file mode 100644 (file)
index 0000000..3357cc8
--- /dev/null
@@ -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 */
+        };
+    }
+}
index 07cf1b29a3b92708dc10d73274aaa87a110d9b57..933f56d6dcd6f0d301537f083aba843b0c289eb9 100644 (file)
  *
  */
 
+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);
     }
 }
index f6d9ddcb26672618fd2dd5caca9bf3040d9f5c79..6728913d5f8ba28826640024190c573d44329230 100644 (file)
@@ -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();
+        }
     }
 }