--- /dev/null
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
--- /dev/null
+<manifest>
+ <request>
+ <domain name="_"/>
+ </request>
+</manifest>
--- /dev/null
+Name: csapi-uix-tts-engine
+Summary: Tizen Uix tts engine API for C#
+Version: 1.0.2
+Release: 1
+Group: Development/Libraries
+License: Apache-2.0
+URL: https://www.tizen.org
+Source0: %{name}-%{version}.tar.gz
+Source1: %{name}.manifest
+
+AutoReqProv: no
+ExcludeArch: aarch64
+
+BuildRequires: dotnet-build-tools
+
+# C# API Requires
+BuildRequires: csapi-tizen-nuget
+
+%define Assemblies Tizen.Uix.TtsEngine
+
+%description
+%{summary}
+
+%dotnet_import_sub_packages
+
+%prep
+%setup -q
+cp %{SOURCE1} .
+
+%build
+for ASM in %{Assemblies}; do
+%dotnet_build $ASM
+%dotnet_pack $ASM/$ASM.nuspec %{version}
+done
+
+%install
+for ASM in %{Assemblies}; do
+%dotnet_install $ASM
+done
+
+%files
+%manifest %{name}.manifest
+%license LICENSE
+%attr(644,root,root) %{dotnet_assembly_files}
--- /dev/null
+/*
+* Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the License);
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an AS IS BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+
+/// <summary>
+/// Partial Interop Class
+/// </summary>
+internal static partial class Interop
+{
+ /// <summary>
+ /// Partial Libraries Class
+ /// </summary>
+ internal static partial class Libraries
+ {
+ internal const string TtsEngine = "libtts_engine.so";
+ }
+}
--- /dev/null
+/*
+* Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the License);
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an AS IS BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+
+using System;
+using System.Runtime.InteropServices;
+using Tizen.Uix.TtsEngine;
+using static Tizen.Uix.TtsEngine.Engine;
+
+/// <summary>
+/// Partial Interop Class
+/// </summary>
+internal static partial class Interop
+{
+ /// <summary>
+ /// TtsEngine Interop Class
+ /// </summary>
+ internal static class TtsEngine
+ {
+ internal static string LogTag = "Tizen.Uix.TtsEngine";
+
+ private const int ErrorTts = -0x02F10000;
+
+ public enum ErrorCode
+ {
+ 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 */
+ NetworkDown = Tizen.Internals.Errors.ErrorCode.Networkdown, /**< Network down(Out of network) */
+ PermissionDenied = Tizen.Internals.Errors.ErrorCode.PermissionDenied, /**< Permission denied */
+ InvalidState = ErrorTts | 0x01, /**< Invalid state */
+ InvalidVoice = ErrorTts | 0x02, /**< Invalid voice */
+ OperationFailed = ErrorTts | 0x04, /**< Operation failed */
+ NotSupportedFeature = ErrorTts | 0x06, /**< Not supported feature of current engine */
+ NotSupported = Tizen.Internals.Errors.ErrorCode.NotSupported, /**< Device or resource busy */
+ };
+
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate Error InitializeCb();
+
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate Error DeinitializeCb();
+
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate Error ForEachSupportedVoicesCb(SupportedVoice cb, IntPtr userData);
+
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate Error IsValidVoiceCb(string language, int type, out bool isValid);
+
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate Error SetPitchCb(int pitch);
+
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate Error LoadVoiceCb(string langauge, int type);
+
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate Error UnloadVoiceCb(string language, int type);
+
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate Error CheckAppAgreedCb(string appid, out bool isAgreed);
+
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate bool NeedAppCredentialCb();
+
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate Error StartSynthesisCb(IntPtr language, int type, IntPtr text, int speed, IntPtr appid, IntPtr credential, IntPtr userData);
+
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate Error CancelSynthesisCb();
+
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate Error GetInfoCb(out IntPtr engineUuid, out IntPtr engineName, out IntPtr engineSetting, out int useNetwork);
+
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate Error PrivateDataSetCb(string key, string data);
+
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate Error PrivateDataRequestedCb(string key, out string data);
+
+ [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
+ internal struct RequestCallbackStruct
+ {
+ internal int version;
+ [MarshalAs(UnmanagedType.FunctionPtr)]
+ internal GetInfoCb getInfo;
+ [MarshalAs(UnmanagedType.FunctionPtr)]
+ internal InitializeCb initialize;
+ [MarshalAs(UnmanagedType.FunctionPtr)]
+ internal DeinitializeCb deinitialize;
+ [MarshalAs(UnmanagedType.FunctionPtr)]
+ internal ForEachSupportedVoicesCb supportedVoice;
+ [MarshalAs(UnmanagedType.FunctionPtr)]
+ internal IsValidVoiceCb validVoice;
+ [MarshalAs(UnmanagedType.FunctionPtr)]
+ internal SetPitchCb pitch;
+ [MarshalAs(UnmanagedType.FunctionPtr)]
+ internal LoadVoiceCb loadVoice;
+ [MarshalAs(UnmanagedType.FunctionPtr)]
+ internal UnloadVoiceCb unloadVoice;
+ [MarshalAs(UnmanagedType.FunctionPtr)]
+ internal StartSynthesisCb startSynthesis;
+ [MarshalAs(UnmanagedType.FunctionPtr)]
+ internal CancelSynthesisCb cancelSynthesis;
+ [MarshalAs(UnmanagedType.FunctionPtr)]
+ internal CheckAppAgreedCb checkAppAgreed;
+ [MarshalAs(UnmanagedType.FunctionPtr)]
+ internal NeedAppCredentialCb needAppCredential;
+ };
+
+ internal sealed class CallbackStructGCHandle : IDisposable
+ {
+ internal RequestCallbackStruct CallbackStruct;
+ internal GCHandle CallbackStructHandle;
+ public CallbackStructGCHandle()
+ {
+ CallbackStruct = new RequestCallbackStruct();
+ CallbackStructHandle = GCHandle.Alloc(CallbackStruct);
+ }
+
+ #region IDisposable Support
+ private bool disposedValue = false;
+
+ void Dispose(bool disposing)
+ {
+ Tizen.Log.Info(LogTag, "In Dispose");
+ if (!disposedValue)
+ {
+ if (disposing)
+ {
+ Tizen.Log.Info(LogTag, "In Dispose free called");
+ CallbackStructHandle.Free();
+ }
+
+ disposedValue = true;
+ }
+ }
+
+ public void Dispose()
+ {
+ Dispose(true);
+ }
+ #endregion
+ }
+
+ [DllImport(Libraries.TtsEngine, EntryPoint = "ttse_main")]
+ internal static extern Error TTSEMain(int argc, string[] argv, IntPtr callback);
+
+ [DllImport(Libraries.TtsEngine, EntryPoint = "ttse_get_speed_range")]
+ internal static extern Error TTSEGetSpeedRange(out int min, out int normal, out int max);
+
+ [DllImport(Libraries.TtsEngine, EntryPoint = "ttse_get_pitch_range")]
+ internal static extern Error TTSEGetPitchRange(out int min, out int normal, out int max);
+
+ [DllImport(Libraries.TtsEngine, EntryPoint = "ttse_send_result")]
+ internal static extern Error TTSESendResult(ResultEvent resultEvent, IntPtr data, int dataSize, AudioType audioType, int rate, IntPtr userData);
+
+ [DllImport(Libraries.TtsEngine, EntryPoint = "ttse_send_error")]
+ internal static extern Error TTSESendError(Error error, string msg);
+
+ [DllImport(Libraries.TtsEngine, EntryPoint = "ttse_set_private_data_set_cb")]
+ internal static extern Error TTSESetPrivateDataSetCb(PrivateDataSetCb callbackFunc);
+
+ [DllImport(Libraries.TtsEngine, EntryPoint = "ttse_set_private_data_requested_cb")]
+ internal static extern Error TTSESetPrivateDataRequestedCb(PrivateDataRequestedCb callbackFunc);
+ }
+}
--- /dev/null
+<Project Sdk="Microsoft.NET.Sdk">
+
+ <PropertyGroup>
+ <TargetFramework>netstandard1.3</TargetFramework>
+ <AllowUnsafeBlocks>True</AllowUnsafeBlocks>
+ <SignAssembly>True</SignAssembly>
+ <AssemblyOriginatorKeyFile>Tizen.Uix.TtsEngine.snk</AssemblyOriginatorKeyFile>
+ <PublicSign Condition="'$(OS)' != 'Windows_NT'">true</PublicSign>
+ <GenerateReferenceAssembly>True</GenerateReferenceAssembly>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <PackageReference Include="Tizen" Version="1.0.5" />
+ </ItemGroup>
+
+</Project>
\ No newline at end of file
--- /dev/null
+/*
+* Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the License);
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an AS IS BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+using static Interop.TtsEngine;
+
+
+namespace Tizen.Uix.TtsEngine
+{
+ internal static class ExceptionFactory
+ {
+ internal static Exception CreateException(ErrorCode err)
+ {
+ Tizen.Log.Error(LogTag, "Error " + err);
+ Exception exp;
+ switch (err)
+ {
+ case ErrorCode.OutOfMemory:
+ {
+ exp = new OutOfMemoryException("Out Of Memory");
+ break;
+ }
+
+ case ErrorCode.IoError:
+ {
+ exp = new InvalidOperationException("I/O Error Occured");
+ break;
+ }
+
+ case ErrorCode.InvalidParameter:
+ {
+ exp = new ArgumentException("Invalid Parameters Provided");
+ break;
+ }
+
+ case ErrorCode.NetworkDown:
+ {
+ exp = new InvalidOperationException("Network down(Out of network)");
+ break;
+ }
+
+ case ErrorCode.InvalidState:
+ {
+ exp = new InvalidOperationException("Invalid state");
+ break;
+ }
+
+ case ErrorCode.InvalidVoice:
+ {
+ exp = new InvalidOperationException("Invalid Voice");
+ break;
+ }
+
+ case ErrorCode.OperationFailed:
+ {
+ exp = new InvalidOperationException("Operation Failed");
+ break;
+ }
+
+ case ErrorCode.NotSupportedFeature:
+ {
+ exp = new InvalidOperationException("Not supported feature");
+ break;
+ }
+
+ case ErrorCode.NotSupported:
+ {
+ exp = new NotSupportedException("Not supported");
+ break;
+ }
+
+ case ErrorCode.PermissionDenied:
+ {
+ exp = new UnauthorizedAccessException("Permission Denied");
+ break;
+ }
+
+ default:
+ {
+ exp = new Exception("");
+ break;
+ }
+ }
+
+ return exp;
+ }
+ }
+}
--- /dev/null
+/*
+* Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the License);
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an AS IS BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+using System.Runtime.InteropServices;
+using static Interop.TtsEngine;
+
+namespace Tizen.Uix.TtsEngine
+{
+ /// <summary>
+ /// Enumeration for audio type.
+ /// </summary>
+ public enum AudioType
+ {
+ /// <summary>
+ /// Signed 16-bit audio type
+ /// </summary>
+ RawS16 = 0,
+ /// <summary>
+ /// Unsigned 8-bit audio type
+ /// </summary>
+ RawU8,
+ /// <summary>
+ /// Maximum Value
+ /// </summary>
+ Max
+ };
+
+ /// <summary>
+ /// Enumeration for result.
+ /// </summary>
+ public enum ResultEvent
+ {
+ /// <summary>
+ /// Event when the voice synthesis is failed
+ /// </summary>
+ Fail = -1,
+ /// <summary>
+ /// Event when the sound data is first data by callback function
+ /// </summary>
+ Start = 1,
+ /// <summary>
+ /// Event when the next sound data exist, not first and not last
+ /// </summary>
+ Continue = 2,
+ /// <summary>
+ /// Event when the sound data is last data or sound data is only one result
+ /// </summary>
+ Finish = 3
+ };
+
+ /// <summary>
+ /// Enumeration for Voice Type
+ /// </summary>
+ public enum VoiceType
+ {
+ /// <summary>
+ /// male voice type.
+ /// </summary>
+ Male = 1,
+ /// <summary>
+ /// female voice type.
+ /// </summary>
+ Female = 2,
+ /// <summary>
+ /// child's voice type.
+ /// </summary>
+ Child = 3
+ }
+
+ /// <summary>
+ /// Enum for Error values that can occur
+ /// </summary>
+ public enum Error
+ {
+ /// <summary>
+ /// Successful, No error
+ /// </summary>
+ None = ErrorCode.None,
+ /// <summary>
+ /// Out of Memory
+ /// </summary>
+ OutOfMemory = ErrorCode.OutOfMemory,
+ /// <summary>
+ /// I/O error
+ /// </summary>
+ IoError = ErrorCode.IoError,
+ /// <summary>
+ /// Invalid parameter
+ /// </summary>
+ InvalidParameter = ErrorCode.InvalidParameter,
+ /// <summary>
+ /// Network down(Out of network)
+ /// </summary>
+ NetworkDown = ErrorCode.NetworkDown,
+ /// <summary>
+ /// Invalid state
+ /// </summary>
+ InvalidState = ErrorCode.InvalidState,
+ /// <summary>
+ /// Invalid voice
+ /// </summary>
+ InvalidVoice = ErrorCode.InvalidVoice,
+ /// <summary>
+ /// Operation failed
+ /// </summary>
+ OperationFailed = ErrorCode.OperationFailed,
+ /// <summary>
+ /// Not supported feature of current engine
+ /// </summary>
+ NotSupportedFeature = ErrorCode.NotSupportedFeature,
+ /// <summary>
+ /// NOT supported
+ /// </summary>
+ NotSupported = ErrorCode.NotSupported,
+ /// <summary>
+ /// Permission denied
+ /// </summary>
+ PermissionDenied = ErrorCode.PermissionDenied
+ };
+
+ /// <summary>
+ /// This Class represents the Tts Engine which has to be inherited to make the engine.
+ /// </summary>
+ public abstract class Engine
+ {
+ private CallbackStructGCHandle _callbackStructGCHandle = new CallbackStructGCHandle();
+ private PrivateDataSetCb _privateDataSetCb;
+ private Action<string> _privateDatacallback;
+ private PrivateDataRequestedCb _privateDataRequestedCb;
+ private OutAction<string> _privateDataRequestedCallback;
+ private static Engine _engine;
+ private IntPtr _structIntPtrHandle;
+
+ /// <summary>
+ /// An Action with 2 Input Parameter returning a Error
+ /// </summary>
+ /// <typeparam name="T">Generic Type for Parameter 1</typeparam>
+ /// <param name="a">The Input Parameter 1</param>
+ /// <param name="b">The Input Parameter 2</param>
+ /// <returns>Error Value</returns>
+ public delegate Error Action<T>(T a, T b);
+
+ /// <summary>
+ /// An Action with 2 Out Parameter returning a Error
+ /// </summary>
+ /// <typeparam name="T">Generic Type for Parameter 1</typeparam>
+ /// <param name="a">The Input Parameter 1</param>
+ /// <param name="b">The Input Parameter 2</param>
+ /// <returns>Error Value</returns>
+ public delegate Error OutAction<T>(T a, out T b);
+
+ /// <summary>
+ /// Called when TTS engine informs the engine service user about whole supported language and voice type list.
+ /// This callback function is implemented by the engine service user.Therefore, the engine developer does NOT have to implement this callback function.
+ /// </summary>
+ /// <remarks>
+ /// This callback function is called by ForEachSupportedVoices() to inform the whole supported voice list. userData must be transferred from ForEachSupportedVoices().
+ /// </remarks>
+ /// <param name="language">The language is specified as an ISO 3166 alpha-2 two-letter country code followed by ISO 639-1 for the two-letter language code.
+ /// For example, "ko_KR" for Korean, "en_US" for American English</param>
+ /// <param name="type">The voice type</param>
+ /// <param name="userData">The user data passed from ForEachSupportedVoices()</param>
+ /// <returns>true to continue with the next iteration of the loop false to break out of the loop</returns>
+ /// <precondition>ForEachSupportedVoices() will invoke this callback function.</precondition>
+ public delegate bool SupportedVoice(string language, VoiceType type, IntPtr userData);
+
+ /// <summary>
+ /// Called when the engine service user starts to synthesize a voice, asynchronously.
+ /// </summary>
+ /// <remarks>
+ /// In this callback function, TTS engine must transfer the synthesized result to the engine service user using SendResult().
+ /// Also, if TTS engine needs the application's credential, it can set the credential granted to the application.
+ /// </remarks>
+ /// <param name="language">The language is specified as an ISO 3166 alpha-2 two-letter country code followed by ISO 639-1 for the two-letter language code.
+ /// For example, "ko_KR" for Korean, "en_US" for American English</param>
+ /// <param name="type">The voice type</param>
+ /// <param name="text">Texts</param>
+ /// <param name="speed">The speed of speaking</param>
+ /// <param name="appid">The Application ID</param>
+ /// <param name="credential">The credential granted to the application</param>
+ /// <param name="userData">The user data which must be passed to SendResult() function</param>
+ /// <returns>
+ /// Following Error Codes can be returned
+ /// 1. None
+ /// 2. InvalidState
+ /// 3. InvalidParameter
+ /// 4. InvalidVoice
+ /// 5. OperationFailed
+ /// 6. NetworkDown
+ /// 7. PermissionDenied
+ /// </returns>
+ /// <postcondition>This function invokes SendResult()</postcondition>
+ public abstract Error StartSynthesis(string language, int type, string text, int speed, string appid, string credential, IntPtr userData);
+
+ /// <summary>
+ /// Called when the engine service user requests the basic information of TTS engine.
+ /// </summary>
+ /// <remarks>
+ /// The allocated engineUuid, engineName, and engineSetting will be released internally.
+ /// In order to upload the engine at Tizen Appstore, both a service app and a ui app are necessary.
+ /// Therefore, engineSetting must be transferred to the engine service user.
+ /// </remarks>
+ /// <param name="engineUuid">UUID of engine</param>
+ /// <param name="engineName">Name of engine</param>
+ /// <param name="engineSetting">The engine setting application(ui app)'s app ID</param>
+ /// <param name="useNetwork">The status for using network</param>
+ /// <returns>
+ /// Following Error Codes can be returned
+ /// 1. None
+ /// 2. InvalidState
+ /// </returns>
+ public abstract Error GetInformation(out string engineUuid, out string engineName, out string engineSetting, out bool useNetwork);
+
+ /// <summary>
+ /// Called when the engine service user initializes TTS engine.
+ /// </summary>
+ /// <returns>
+ /// Following Error Codes can be returned
+ /// 1. None
+ /// 2. InvalidState
+ /// 3. NotSupportedFeature
+ /// 4. PermissionDenied
+ /// </returns>
+ public abstract Error Initialize();
+
+ /// <summary>
+ /// Called when the engine service user deinitializes TTS engine.
+ /// </summary>
+ /// <remarks>
+ /// NOTE that the engine may be terminated automatically. When this callback function is invoked, the release of resources is necessary.
+ /// </remarks>
+ /// <returns>
+ /// Following Error Codes can be returned
+ /// 1. None
+ /// 2. InvalidState
+ /// </returns>
+ public abstract Error Deinitialize();
+
+ /// <summary>
+ /// Called when the engine service user gets the whole supported voice list.
+ /// </summary>
+ /// <remarks>
+ /// In this function, the engine service user's callback function 'SupportedVoice()' is invoked repeatedly for getting all supported voices,
+ /// and userData must be transferred to 'SupportedVoice()'. If 'SupportedVoice()' returns false, it should be stopped to call 'SupportedVoice()'.</remarks>
+ /// <param name="callback">The callback function</param>
+ /// <param name="userData">The user data which must be passed to SupportedVoice()</param>
+ /// <returns>
+ /// Following Error Codes can be returned
+ /// 1. None
+ /// 2. OperationFailed
+ /// </returns>
+ /// <postcondition>This callback function invokes SupportedVoice() repeatedly for getting all supported voices.</postcondition>
+ public abstract Error ForEachSupportedVoices(SupportedVoice callback, IntPtr userData);
+
+ /// <summary>
+ /// Called when the engine service user checks whether the voice is valid or not in TTS engine.
+ /// </summary>
+ /// <param name="language">The language is specified as an ISO 3166 alpha-2 two-letter country code followed by ISO 639-1 for the two-letter language code.
+ /// For example, "ko_KR" for Korean, "en_US" for American English</param>
+ /// <param name="type">The voice type</param>
+ /// <param name="isValid">A variable for checking whether the corresponding voice is valid or not. true to be valid, false to be invalid</param>
+ /// <returns>
+ /// Following Error Codes can be returned
+ /// 1. None
+ /// 2. InvalidParameter
+ /// </returns>
+ public abstract Error IsValidVoice(string language, int type, out bool isValid);
+
+ /// <summary>
+ /// Called when the engine service user sets the default pitch of TTS engine.
+ /// </summary>
+ /// <param name="pitch">The default pitch</param>
+ /// <returns>
+ /// Following Error Codes can be returned
+ /// 1. None
+ /// 2. InvalidState
+ /// 3. OperationFailed
+ /// 4. InvalidParameter
+ /// </returns>
+ public abstract Error SetPitch(int pitch);
+
+ /// <summary>
+ /// Called when the engine service user requests to load the corresponding voice type for the first time.
+ /// </summary>
+ /// <param name="language">The language is specified as an ISO 3166 alpha-2 two-letter country code followed by ISO 639-1 for the two-letter language code.
+ /// For example, "ko_KR" for Korean, "en_US" for American English</param>
+ /// <param name="type">The voice type</param>
+ /// <returns>
+ /// Following Error Codes can be returned
+ /// 1. None
+ /// 2. InvalidState
+ /// 3. OperationFailed
+ /// 4. InvalidVoice
+ /// 5. InvalidParameter
+ /// 6. OutOfMemory
+ /// </returns>
+ public abstract Error LoadVoice(string language, int type);
+
+ /// <summary>
+ /// Called when the engine service user requests to unload the corresponding voice type or to stop using voice.
+ /// </summary>
+ /// <param name="language">The language is specified as an ISO 3166 alpha-2 two-letter country code followed by ISO 639-1 for the two-letter language code.
+ /// For example, "ko_KR" for Korean, "en_US" for American English</param>
+ /// <param name="type">The voice type</param>
+ /// <returns>
+ /// Following Error Codes can be returned
+ /// 1. None
+ /// 2. InvalidState
+ /// 3. OperationFailed
+ /// 4. InvalidVoice
+ /// 5. InvalidParameter
+ /// </returns>
+ public abstract Error UnloadVoice(string language, int type);
+
+ /// <summary>
+ /// Called when the engine service user requests for TTS engine to check whether the application agreed the usage of TTS engine.
+ /// This callback function is called when the engine service user requests for TTS engine to check the application's agreement about using the engine.
+ /// According to the need, the engine developer can provide some user interfaces to check the agreement.
+ /// </summary>
+ /// <remarks>
+ /// If the TTS engine developer wants not to check the agreement, the developer has need to return proper values as isAgreed in accordance with the intention.
+ /// true if the developer regards that every application agreed the usage of the engine, false if the developer regards that every application disagreed.
+ /// NOTE that, however, there may be any legal issue unless the developer checks the agreement.
+ /// Therefore, we suggest that the engine developers should provide a function to check the agreement.
+ /// </remarks>
+ /// <param name="appid">The Application ID</param>
+ /// <param name="isAgreed">A variable for checking whether the application agreed to use TTS engine or not. true to agree, false to disagree</param>
+ /// <returns>
+ /// Following Error Codes can be returned
+ /// 1. None
+ /// 2. InvalidState
+ /// 3. NotSupportedFeature
+ /// 4. InvalidParameter
+ /// </returns>
+ public abstract Error CheckAppAgreed(string appid, out bool isAgreed);
+
+ /// <summary>
+ /// Called when the engine service user checks whether TTS engine needs the application's credential.
+ /// </summary>
+ /// <returns> true if TTS engine needs the application's credential, otherwise false </returns>
+ public abstract bool NeedAppCredential();
+
+ /// <summary>
+ /// Called when the engine service user cancels to synthesize a voice.
+ /// </summary>
+ /// <returns>
+ /// Following Error Codes can be returned
+ /// 1. None
+ /// 2. InvalidState
+ /// </returns>
+ /// <percondition>
+ /// StartSynthesis should be performed
+ /// </percondition>
+ public abstract Error CancelSynthesis();
+
+ /// <summary>
+ /// Public Constructor
+ /// </summary>
+ public Engine()
+ {
+ _engine = this;
+ }
+
+ /// <summary>
+ /// Main function for Text-To-Speech (TTS) engine.
+ /// This function is the main function for operating TTS engine.
+ /// </summary>
+ /// <remarks>
+ /// ServiceAppMain should be used for working the engine after this function.
+ /// </remarks>
+ /// <param name="argc">The argument count(original)</param>
+ /// <param name="argv">The argument(original)</param>
+ /// <exception cref="ArgumentException">Thrown in case of Invalid Parameter</exception>
+ /// <exception cref="NotSupportedException">Thrown in case of Not supported</exception>
+ /// <exception cref="InvalidOperationException">thrown in case of Operation failure</exception>
+ public void EngineMain(int argc, string[] argv)
+ {
+ _callbackStructGCHandle.CallbackStruct.version = 1;
+ _callbackStructGCHandle.CallbackStruct.getInfo = _getInfoCb;
+ _callbackStructGCHandle.CallbackStruct.initialize = Initialize;
+ _callbackStructGCHandle.CallbackStruct.deinitialize = _deinitializeCb;
+ _callbackStructGCHandle.CallbackStruct.supportedVoice = ForEachSupportedVoices;
+ _callbackStructGCHandle.CallbackStruct.validVoice = IsValidVoice;
+ _callbackStructGCHandle.CallbackStruct.pitch = SetPitch;
+ _callbackStructGCHandle.CallbackStruct.loadVoice = LoadVoice;
+ _callbackStructGCHandle.CallbackStruct.unloadVoice = UnloadVoice;
+ _callbackStructGCHandle.CallbackStruct.startSynthesis = _startSynthesisCb;
+ _callbackStructGCHandle.CallbackStruct.cancelSynthesis = CancelSynthesis;
+ _callbackStructGCHandle.CallbackStruct.checkAppAgreed = CheckAppAgreed;
+ _callbackStructGCHandle.CallbackStruct.needAppCredential = NeedAppCredential;
+ _structIntPtrHandle = Marshal.AllocHGlobal(Marshal.SizeOf(_callbackStructGCHandle.CallbackStruct));
+ Marshal.StructureToPtr<RequestCallbackStruct>(_callbackStructGCHandle.CallbackStruct, _structIntPtrHandle, false);
+ Error error = TTSEMain(argc, argv, _structIntPtrHandle);
+ if (error != Error.None)
+ {
+ Log.Error(LogTag, "TTSEMain Failed with error " + error);
+ throw ExceptionFactory.CreateException((ErrorCode)error);
+ }
+
+ Log.Info(LogTag, "After TTSEMain");
+ }
+
+ /// <summary>
+ /// Gets the speed range from Tizen platform
+ /// </summary>
+ /// <remarks>
+ /// This API is used when TTS engine wants to get the speed range from Tizen platform
+ /// </remarks>
+ /// <param name="min">The minimum speed value</param>
+ /// <param name="normal">The normal speed value</param>
+ /// <param name="max">The maximum speed value</param>
+ /// <exception cref="NotSupportedException">Thrown in case of Not supported</exception>
+ /// <exception cref="InvalidOperationException">thrown in case of Operation failure</exception>
+ public void GetSpeedRange(out int min, out int normal, out int max)
+ {
+ Error error = TTSEGetSpeedRange(out min, out normal, out max);
+ if (error != Error.None)
+ {
+ Log.Error(LogTag, "TTSEGetSpeedRange Failed with error " + error);
+ throw ExceptionFactory.CreateException((ErrorCode)error);
+ }
+
+ }
+
+ /// <summary>
+ /// Gets the pitch range from Tizen platform.
+ /// </summary>
+ /// <remarks>
+ /// This API is used when TTS engine wants to get the pitch range from Tizen platform.
+ /// </remarks>
+ /// <param name="min">The minimum pitch value</param>
+ /// <param name="normal">The normal pitch value</param>
+ /// <param name="max">The maximum pitch value</param>
+ /// <exception cref="NotSupportedException">Thrown in case of Not supported</exception>
+ /// <exception cref="InvalidOperationException">thrown in case of Operation failure</exception>
+ public void GetPitchRange(out int min, out int normal, out int max)
+ {
+ Error error = TTSEGetPitchRange(out min, out normal, out max);
+ if (error != Error.None)
+ {
+ Log.Error(LogTag, "TTSEGetPitchRange Failed with error " + error);
+ throw ExceptionFactory.CreateException((ErrorCode)error);
+ }
+
+ }
+
+ /// <summary>
+ /// Sends the synthesized result to the engine service user.
+ /// </summary>
+ /// <remarks>
+ /// This API is used in StartSynthesis(), when TTS engine sends the synthesized result to the engine service user.
+ /// The synthesized result must be transferred to the engine service user through this function.
+ /// </remarks>
+ /// <param name="resultEvent">The result event</param>
+ /// <param name="data">Result data</param>
+ /// <param name="dataSize">Result data size</param>
+ /// <param name="audioType">The audio type</param>
+ /// <param name="rate">The sample rate</param>
+ /// <exception cref="ArgumentException">Thrown in case of Invalid Parameter</exception>
+ /// <exception cref="NotSupportedException">Thrown in case of Not supported</exception>
+ /// <exception cref="InvalidOperationException">thrown in case of Operation failure</exception>
+ /// <precondition>
+ /// EngineMain function should be invoked before this function is called. StartSynthesis() will invoke this function.
+ /// </precondition>
+ public void SendResult(ResultEvent resultEvent, IntPtr data, int dataSize, AudioType audioType, int rate)
+ {
+ Error error = TTSESendResult(resultEvent, data, dataSize, audioType, rate, IntPtr.Zero);
+ if (error != Error.None)
+ {
+ Log.Error(LogTag, "TTSESendResult Failed with error " + error);
+ throw ExceptionFactory.CreateException((ErrorCode)error);
+ }
+ }
+
+ /// <summary>
+ /// Sends the error to the engine service user.
+ /// </summary>
+ /// <param name="error">The error reason</param>
+ /// <param name="msg">The error message</param>
+ /// <precondition>
+ /// EngineMain function should be invoked before this function is called.
+ /// </precondition>
+ public void SendError(Error error, string msg)
+ {
+ Error err = TTSESendError(error, msg);
+ if (err != Error.None)
+ {
+ Log.Error(LogTag, "SendError Failed with error " + err);
+ throw ExceptionFactory.CreateException((ErrorCode)error);
+ }
+
+ }
+
+ /// <summary>
+ /// Sets a callback function for setting the private data.
+ /// </summary>
+ /// <param name="callback">
+ /// Called when the engine service user gets the private data from Tts engine.
+ /// In Parameters:
+ /// a = Key -- The key field of private data
+ /// b = data -- The data field of private data
+ /// Following Error Codes can be returned
+ /// 1. None
+ /// 2. InvalidParameter
+ /// 3. OperationFailed
+ /// 4. NotSupported
+ /// </param>
+ /// <exception cref="ArgumentException">Thrown in case of Invalid Parameter</exception>
+ /// <exception cref="UnauthorizedAccessException">Thrown in case of Permission denied</exception>
+ /// <exception cref="NotSupportedException">Thrown in case of Not supported</exception>
+ /// <exception cref="InvalidOperationException">thrown in case of Operation failure</exception>
+ /// <precondition>
+ /// Main function should be invoked before this function is called.
+ /// </precondition>
+ public void SetPrivateDataSetDelegate(Action<string> callback)
+ {
+ _privateDatacallback = callback;
+ _privateDataSetCb = (string key, string data) =>
+ {
+ return _privateDatacallback.Invoke(key, data);
+ };
+ Error error = TTSESetPrivateDataSetCb(_privateDataSetCb);
+ if (error != Error.None)
+ {
+ Log.Error(LogTag, "SetPrivateDataSetDelegate Failed with error " + error);
+ throw ExceptionFactory.CreateException((ErrorCode)error);
+ }
+
+ }
+
+ /// <summary>
+ /// Sets a callback function for setting the private data.
+ /// </summary>
+ /// <param name="callback">callback function
+ /// Called when TTS engine receives the private data from the engine service user.
+ /// This callback function is called when the engine service user sends the private data to TTS engine.
+ /// Out Parameters:
+ /// a = Key -- The key field of private data
+ /// b = data -- The data field of private data
+ /// Following Error Codes can be returned
+ /// 1. None
+ /// 2. InvalidParameter
+ /// 3. OperationFailed
+ /// 4. NotSupported
+ /// </param>
+ /// <exception cref="ArgumentException">Thrown in case of Invalid Parameter</exception>
+ /// <exception cref="UnauthorizedAccessException">Thrown in case of Permission denied</exception>
+ /// <exception cref="NotSupportedException">Thrown in case of Not supported</exception>
+ /// <exception cref="InvalidOperationException">thrown in case of Operation failure</exception>
+ /// <precondition>
+ /// Main function should be invoked before this function is called.
+ /// </precondition>
+ public void SetPrivateDataRequestedDelegate(OutAction<string> callback)
+ {
+ _privateDataRequestedCallback = callback;
+ _privateDataRequestedCb = (string key, out string data) =>
+ {
+ return _privateDataRequestedCallback.Invoke(key, out data);
+ };
+ Error error = TTSESetPrivateDataRequestedCb(_privateDataRequestedCb);
+ if (error != Error.None)
+ {
+ Log.Error(LogTag, "SetPrivateDataRequestedDelegate Failed with error " + error);
+ throw ExceptionFactory.CreateException((ErrorCode)error);
+ }
+
+ }
+ private StartSynthesisCb _startSynthesisCb = (IntPtr language, int type, IntPtr text, int speed, IntPtr appid, IntPtr credential, IntPtr userData) =>
+ {
+ string lan = null;
+ string txt = null;
+ string apid = null;
+ string cre = null;
+ if (language != null)
+ lan = Marshal.PtrToStringAnsi(language);
+ if (text != null)
+ txt = Marshal.PtrToStringAnsi(text);
+ if (appid != null)
+ apid = Marshal.PtrToStringAnsi(appid);
+ if (credential != null)
+ cre = Marshal.PtrToStringAnsi(credential);
+ return _engine.StartSynthesis(lan, type, txt, speed, apid, cre, IntPtr.Zero);
+ };
+
+ private GetInfoCb _getInfoCb = (out IntPtr engineUuid, out IntPtr engineName, out IntPtr engineSetting, out int useNetwork) =>
+ {
+ string uuid;
+ string name;
+ string setting;
+ bool network;
+ Error err = _engine.GetInformation(out uuid, out name, out setting, out network);
+ if (network == true)
+ {
+ useNetwork = 1;
+ }
+ else
+ {
+ useNetwork = 0;
+ }
+ engineUuid = Marshal.StringToHGlobalAnsi(uuid);
+ engineName = Marshal.StringToHGlobalAnsi(name);
+ engineSetting = Marshal.StringToHGlobalAnsi(setting);
+ return err;
+ };
+
+ private DeinitializeCb _deinitializeCb = () =>
+ {
+ Marshal.FreeHGlobal(_engine._structIntPtrHandle);
+ return _engine.Deinitialize();
+ };
+ }
+}
\ No newline at end of file