b30c70cc2c1e394eeea3f57f9e808c3f404c6c05
[platform/core/csapi/uix-stt.git] / Tizen.Uix.Stt / Tizen.Uix.Stt / RecognitionResultEventArgs.cs
1 /*
2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17
18 using System;
19 using System.Collections.Generic;
20 using System.Runtime.InteropServices;
21 using static Interop.Stt;
22 using static Tizen.Uix.Stt.ResultTime;
23
24 namespace Tizen.Uix.Stt
25 {
26     /// <summary>
27     /// The recognition result from the engine.
28     /// </summary>
29     public class RecognitionResultEventArgs
30     {
31         private ResultEvent _result;
32         private List<string> _data = new List<string>();
33         private ResultMessage _msg;
34         private int _dataCount;
35
36         internal RecognitionResultEventArgs(ResultEvent e, IntPtr data, int count, string msg)
37         {
38             _result = e;
39             switch (msg)
40             {
41                 case "stt.result.message.none":
42                     {
43                         _msg = ResultMessage.None;
44                         break;
45                     }
46
47                 case "stt.result.message.error.too.soon":
48                     {
49                         _msg = ResultMessage.TooSoon;
50                         break;
51                     }
52
53                 case "stt.result.message.error.too.short":
54                     {
55                         _msg = ResultMessage.TooShort;
56                         break;
57                     }
58
59                 case "stt.result.message.error.too.long":
60                     {
61                         _msg = ResultMessage.TooLong;
62                         break;
63                     }
64
65                 case "stt.result.message.error.too.quiet":
66                     {
67                         _msg = ResultMessage.TooQuiet;
68                         break;
69                     }
70
71                 case "stt.result.message.error.too.loud":
72                     {
73                         _msg = ResultMessage.TooLoud;
74                         break;
75                     }
76
77                 case "stt.result.message.error.too.fast":
78                     {
79                         _msg = ResultMessage.TooFast;
80                         break;
81                     }
82
83             }
84
85             this._dataCount = count;
86
87             _data.Clear();
88             if (count > 0)
89             {
90                 IntPtr[] dataArray = new IntPtr[count];
91                 Marshal.Copy(data, dataArray, 0, count);
92                 foreach (IntPtr handle in dataArray)
93                 {
94                     string info = Marshal.PtrToStringAnsi(handle);
95                     _data.Add(info);
96                 }
97             }
98         }
99
100         /// <summary>
101         /// The result event
102         /// </summary>
103         public ResultEvent Result
104         {
105             get
106             {
107                 return _result;
108             }
109         }
110
111         /// <summary>
112         /// Result texts.
113         /// </summary>
114         public IEnumerable<string> Data
115         {
116             get
117             {
118                 return _data;
119             }
120         }
121
122         /// <summary>
123         /// Returns the Result text count.
124         /// </summary>
125         public int DataCount
126         {
127             get
128             {
129                 return _dataCount;
130             }
131         }
132
133         /// <summary>
134         /// Engine message
135         /// </summary>
136         public ResultMessage Message
137         {
138             get
139             {
140                 return _msg;
141             }
142         }
143     }
144 }