1 |
zoff99 |
2 |
/**
|
2 |
|
|
* Navit, a modular navigation system.
|
3 |
|
|
* Copyright (C) 2005-2008 Navit Team
|
4 |
|
|
*
|
5 |
|
|
* This program is free software; you can redistribute it and/or
|
6 |
|
|
* modify it under the terms of the GNU General Public License
|
7 |
|
|
* version 2 as published by the Free Software Foundation.
|
8 |
|
|
*
|
9 |
|
|
* This program is distributed in the hope that it will be useful,
|
10 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12 |
|
|
* GNU General Public License for more details.
|
13 |
|
|
*
|
14 |
|
|
* You should have received a copy of the GNU General Public License
|
15 |
|
|
* along with this program; if not, write to the
|
16 |
|
|
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
17 |
|
|
* Boston, MA 02110-1301, USA.
|
18 |
|
|
*/
|
19 |
|
|
|
20 |
|
|
#include <stdlib.h>
|
21 |
|
|
#include <glib.h>
|
22 |
|
|
#include "config.h"
|
23 |
|
|
#include "item.h"
|
24 |
|
|
#include "debug.h"
|
25 |
|
|
#include "plugin.h"
|
26 |
|
|
#include "android.h"
|
27 |
|
|
#include "speech.h"
|
28 |
|
|
|
29 |
|
|
struct speech_priv {
|
30 |
|
|
jclass NavitSpeechClass;
|
31 |
|
|
jobject NavitSpeech;
|
32 |
|
|
jmethodID NavitSpeech_say;
|
33 |
|
|
int flags;
|
34 |
|
|
};
|
35 |
|
|
|
36 |
|
|
static int
|
37 |
|
|
speech_android_say(struct speech_priv *this, const char *text)
|
38 |
|
|
{
|
39 |
|
|
char *str=g_strdup(text);
|
40 |
|
|
jstring string;
|
41 |
|
|
int i;
|
42 |
|
|
|
43 |
|
|
if (this->flags & 2) {
|
44 |
|
|
for (i = 0 ; i < strlen(str) ; i++) {
|
45 |
|
|
if (str[i] == 0xc3 && str[i+1] == 0x84) {
|
46 |
|
|
str[i]='A';
|
47 |
|
|
str[i+1]='e';
|
48 |
|
|
}
|
49 |
|
|
if (str[i] == 0xc3 && str[i+1] == 0x96) {
|
50 |
|
|
str[i]='O';
|
51 |
|
|
str[i+1]='e';
|
52 |
|
|
}
|
53 |
|
|
if (str[i] == 0xc3 && str[i+1] == 0x9c) {
|
54 |
|
|
str[i]='U';
|
55 |
|
|
str[i+1]='e';
|
56 |
|
|
}
|
57 |
|
|
if (str[i] == 0xc3 && str[i+1] == 0xa4) {
|
58 |
|
|
str[i]='a';
|
59 |
|
|
str[i+1]='e';
|
60 |
|
|
}
|
61 |
|
|
if (str[i] == 0xc3 && str[i+1] == 0xb6) {
|
62 |
|
|
str[i]='o';
|
63 |
|
|
str[i+1]='e';
|
64 |
|
|
}
|
65 |
|
|
if (str[i] == 0xc3 && str[i+1] == 0xbc) {
|
66 |
|
|
str[i]='u';
|
67 |
|
|
str[i+1]='e';
|
68 |
|
|
}
|
69 |
|
|
if (str[i] == 0xc3 && str[i+1] == 0x9f) {
|
70 |
|
|
str[i]='s';
|
71 |
|
|
str[i+1]='s';
|
72 |
|
|
}
|
73 |
|
|
}
|
74 |
|
|
}
|
75 |
|
|
string = (*jnienv)->NewStringUTF(jnienv, str);
|
76 |
|
|
dbg(0,"enter %s\n",str);
|
77 |
|
|
(*jnienv)->CallVoidMethod(jnienv, this->NavitSpeech, this->NavitSpeech_say, string);
|
78 |
|
|
(*jnienv)->DeleteLocalRef(jnienv, string);
|
79 |
|
|
g_free(str);
|
80 |
|
|
|
81 |
|
|
return 1;
|
82 |
|
|
}
|
83 |
|
|
|
84 |
|
|
static void
|
85 |
|
|
speech_android_destroy(struct speech_priv *this) {
|
86 |
|
|
g_free(this);
|
87 |
|
|
}
|
88 |
|
|
|
89 |
|
|
static struct speech_methods speech_android_meth = {
|
90 |
|
|
speech_android_destroy,
|
91 |
|
|
speech_android_say,
|
92 |
|
|
};
|
93 |
|
|
|
94 |
|
|
static int
|
95 |
|
|
speech_android_init(struct speech_priv *ret)
|
96 |
|
|
{
|
97 |
|
|
jmethodID cid;
|
98 |
|
|
char *class="com/zoffcc/applications/zanavi/NavitSpeech2";
|
99 |
|
|
|
100 |
|
|
if (ret->flags & 1)
|
101 |
|
|
class="com/zoffcc/applications/zanavi/NavitSpeech";
|
102 |
|
|
|
103 |
|
|
if (!android_find_class_global(class, &ret->NavitSpeechClass)) {
|
104 |
|
|
dbg(0,"No class found\n");
|
105 |
|
|
return 0;
|
106 |
|
|
}
|
107 |
|
|
dbg(0,"at 3\n");
|
108 |
|
|
cid = (*jnienv)->GetMethodID(jnienv, ret->NavitSpeechClass, "<init>", "(Lcom/zoffcc/applications/zanavi/Navit;)V");
|
109 |
|
|
if (cid == NULL) {
|
110 |
|
|
dbg(0,"no method found\n");
|
111 |
|
|
return 0; /* exception thrown */
|
112 |
|
|
}
|
113 |
|
|
if (!android_find_method(ret->NavitSpeechClass, "say", "(Ljava/lang/String;)V", &ret->NavitSpeech_say))
|
114 |
|
|
return 0;
|
115 |
|
|
dbg(0,"at 4 android_activity=%p\n",android_activity);
|
116 |
|
|
ret->NavitSpeech=(*jnienv)->NewObject(jnienv, ret->NavitSpeechClass, cid, android_activity);
|
117 |
|
|
dbg(0,"result=%p\n",ret->NavitSpeech);
|
118 |
|
|
if (!ret->NavitSpeech)
|
119 |
|
|
return 0;
|
120 |
|
|
if (ret->NavitSpeech)
|
121 |
|
|
(*jnienv)->NewGlobalRef(jnienv, ret->NavitSpeech);
|
122 |
|
|
return 1;
|
123 |
|
|
}
|
124 |
|
|
|
125 |
|
|
static struct speech_priv *
|
126 |
|
|
speech_android_new(struct speech_methods *meth, struct attr **attrs, struct attr *parent) {
|
127 |
|
|
struct speech_priv *this;
|
128 |
|
|
struct attr *flags;
|
129 |
|
|
*meth=speech_android_meth;
|
130 |
|
|
this=g_new0(struct speech_priv,1);
|
131 |
|
|
if (!speech_android_init(this)) {
|
132 |
|
|
g_free(this);
|
133 |
|
|
this=NULL;
|
134 |
|
|
}
|
135 |
|
|
if (android_version < 4)
|
136 |
|
|
this->flags=3;
|
137 |
|
|
if ((flags = attr_search(attrs, NULL, attr_flags)))
|
138 |
|
|
this->flags=flags->u.num;
|
139 |
|
|
|
140 |
|
|
return this;
|
141 |
|
|
}
|
142 |
|
|
|
143 |
|
|
|
144 |
|
|
void
|
145 |
|
|
plugin_init(void)
|
146 |
|
|
{
|
147 |
|
|
plugin_register_speech_type("android", speech_android_new);
|
148 |
|
|
}
|