2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 using System.Runtime.InteropServices;
20 using Tizen.Uix.SttEngine;
21 using static Tizen.Uix.SttEngine.Engine;
24 /// Partial Interop Class
26 internal static partial class Interop
29 /// SttEngine Interop Class
31 internal static class SttEngine
33 internal static string LogTag = "Tizen.Uix.SttEngine";
35 private const int ErrorStt = -0x02F00000;
39 None = Tizen.Internals.Errors.ErrorCode.None, /* Successful */
40 OutOfMemory = Tizen.Internals.Errors.ErrorCode.OutOfMemory, /* Out of Memory */
41 IoError = Tizen.Internals.Errors.ErrorCode.IoError, /* I/O error */
42 InvalidParameter = Tizen.Internals.Errors.ErrorCode.InvalidParameter, /* Invalid parameter */
43 NetworkDown = Tizen.Internals.Errors.ErrorCode.Networkdown, /* Network down(Out of network) */
44 InvalidState = ErrorStt | 0x01, /* Invalid state */
45 InvalidLanguage = ErrorStt | 0x02, /* Invalid language */
46 OperationFailed = ErrorStt | 0x04, /* Operation failed */
47 NotSupportedFeature = ErrorStt | 0x05, /* Not supported feature of current engine */
48 NotSupported = Tizen.Internals.Errors.ErrorCode.NotSupported, /* Device or resource busy */
49 PermissionDenied = Tizen.Internals.Errors.ErrorCode.PermissionDenied, /* Permission denied */
50 RecordingTimedOut = ErrorStt | 0x06, /* Recording timed out */
53 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
54 internal delegate Error InitializeCb();
56 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
57 internal delegate Error DeinitializeCb();
59 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
60 internal delegate Error ForEachSupportedLangsCb(SupportedLanguages cb, IntPtr userData);
62 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
63 internal delegate Error IsValidLanguageCb(IntPtr language, IntPtr isValid);
65 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
66 internal delegate bool SupportSilenceDetectionCb();
68 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
69 internal delegate Error SupportRecognitionTypeCb(string type, out bool isSupported);
71 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
72 internal delegate Error GetRecordingFormatCb(out AudioType types, out int rate, out int channels);
74 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
75 internal delegate Error SetSilenceDetectionCb(bool isSet);
77 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
78 internal delegate Error CheckAppAgreedCb(string appid, out bool isAgreed);
80 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
81 internal delegate bool NeedAppCredentialCb();
83 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
84 internal delegate Error ForEachResultTimeCb(IntPtr timeInfo, ResultTime callback, IntPtr userData);
86 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
87 internal delegate Error StartCb(IntPtr language, IntPtr type, IntPtr appid, IntPtr credential, IntPtr userData);
89 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
90 internal delegate Error SetRecordingDataCb(string data, uint length);
92 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
93 internal delegate Error StopCb();
95 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
96 internal delegate Error CancelCb();
98 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
99 internal delegate Error GetInfoCb(out IntPtr engineUuid, out IntPtr engineName, out IntPtr engineSetting, out IntPtr useNetwork);
101 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
102 internal delegate Error PrivateDataSetCb(string key, string data);
104 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
105 internal delegate Error PrivateDataRequestedCb(string key, out string data);
107 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
108 internal struct RequestCallbackStruct
110 internal int version;
111 [MarshalAs(UnmanagedType.FunctionPtr)]
112 internal GetInfoCb getInfo;
113 [MarshalAs(UnmanagedType.FunctionPtr)]
114 internal InitializeCb initialize;
115 [MarshalAs(UnmanagedType.FunctionPtr)]
116 internal DeinitializeCb deinitialize;
117 [MarshalAs(UnmanagedType.FunctionPtr)]
118 internal ForEachSupportedLangsCb supportedLanaguge;
119 [MarshalAs(UnmanagedType.FunctionPtr)]
120 internal IsValidLanguageCb validLanaguage;
121 [MarshalAs(UnmanagedType.FunctionPtr)]
122 internal SupportSilenceDetectionCb silence;
123 [MarshalAs(UnmanagedType.FunctionPtr)]
124 internal SupportRecognitionTypeCb recognitionType;
125 [MarshalAs(UnmanagedType.FunctionPtr)]
126 internal GetRecordingFormatCb recordingFormat;
127 [MarshalAs(UnmanagedType.FunctionPtr)]
128 internal ForEachResultTimeCb resultTime;
129 [MarshalAs(UnmanagedType.FunctionPtr)]
130 internal SetSilenceDetectionCb silenceDetection;
131 [MarshalAs(UnmanagedType.FunctionPtr)]
132 internal StartCb start;
133 [MarshalAs(UnmanagedType.FunctionPtr)]
134 internal SetRecordingDataCb recordingData;
135 [MarshalAs(UnmanagedType.FunctionPtr)]
136 internal StopCb stop;
137 [MarshalAs(UnmanagedType.FunctionPtr)]
138 internal CancelCb cancel;
139 [MarshalAs(UnmanagedType.FunctionPtr)]
140 internal CheckAppAgreedCb checkAppAgreed;
141 [MarshalAs(UnmanagedType.FunctionPtr)]
142 internal NeedAppCredentialCb needAppCredential;
145 internal sealed class CallbackStructGCHandle : IDisposable
147 internal RequestCallbackStruct CallbackStruct;
148 internal GCHandle CallbackStructHandle;
149 public CallbackStructGCHandle()
151 CallbackStruct = new RequestCallbackStruct();
152 CallbackStructHandle = GCHandle.Alloc(CallbackStruct);
155 #region IDisposable Support
156 private bool disposedValue = false;
158 void Dispose(bool disposing)
160 Tizen.Log.Info(LogTag, "In Dispose");
165 Tizen.Log.Info(LogTag, "In Dispose free called");
166 CallbackStructHandle.Free();
169 disposedValue = true;
173 public void Dispose()
180 [DllImport(Libraries.SttEngine, EntryPoint = "stte_main")]
181 internal static extern Error STTEMain(int argc, string[] argv, IntPtr callback);
183 [DllImport(Libraries.SttEngine, EntryPoint = "stte_send_result")]
184 internal static extern Error STTESendResult(ResultEvent resultEvent, string type, string[] result, int resultCount, string msg, IntPtr timeInfo, IntPtr userData);
186 [DllImport(Libraries.SttEngine, EntryPoint = "stte_send_error")]
187 internal static extern Error STTESendError(Error error, string msg);
189 [DllImport(Libraries.SttEngine, EntryPoint = "stte_send_speech_status")]
190 internal static extern Error STTESendSpeechStatus(SpeechStatus status, IntPtr userData);
192 [DllImport(Libraries.SttEngine, EntryPoint = "stte_set_private_data_set_cb")]
193 internal static extern Error STTESetPrivateDataSetCb(PrivateDataSetCb callbackFunc);
195 [DllImport(Libraries.SttEngine, EntryPoint = "stte_set_private_data_requested_cb")]
196 internal static extern Error STTESetPrivateDataRequestedCb(PrivateDataRequestedCb callbackFunc);