/[zanavi_public1]/navit/navit/speech.c
ZANavi

Contents of /navit/navit/speech.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 41 - (show annotations) (download)
Tue Aug 11 18:50:37 2015 UTC (8 years, 8 months ago) by zoff99
File MIME type: text/plain
File size: 4392 byte(s)
many fixes, and new features
1 /**
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 <glib.h>
21 #include <string.h>
22 #include "debug.h"
23 #include "item.h"
24 #include "speech.h"
25 #include "plugin.h"
26 #include "navit.h"
27
28 struct speech
29 {
30 struct speech_priv *priv;
31 struct speech_methods meth;
32 struct attr **attrs;
33 };
34
35
36 struct speech *
37 speech_new(struct attr *parent, struct attr **attrs)
38 {
39 struct speech *this_;
40 struct speech_priv *(*speech_new)(struct speech_methods *meth, struct attr **attrs, struct attr *parent);
41 struct attr *attr;
42
43 attr=attr_search(attrs, NULL, attr_type);
44 if (! attr)
45 {
46 dbg(0,"type missing\n");
47 return NULL;
48 }
49
50 dbg(1,"type='%s'\n", attr->u.str);
51
52 #ifdef PLUGSSS
53 speech_new=plugin_get_speech_type(attr->u.str);
54
55 dbg(1,"new=%p\n", speech_new);
56
57 if (! speech_new)
58 {
59 dbg(0,"wrong type '%s'\n", attr->u.str);
60 return NULL;
61 }
62 #endif
63
64
65 this_=g_new0(struct speech, 1);
66
67 #ifdef PLUGSSS
68 this_->priv=speech_new(&this_->meth, attrs, parent);
69 #else
70 this_->priv = speech_android_new(&this_->meth, attrs, parent);
71 #endif
72
73 this_->attrs=attr_list_dup(attrs);
74 dbg(1, "say=%p\n", this_->meth.say);
75 dbg(1,"priv=%p\n", this_->priv);
76
77 if (! this_->priv)
78 {
79 attr_list_free(this_->attrs);
80 g_free(this_);
81 return NULL;
82 }
83
84 dbg(1,"return %p\n", this_);
85
86 return this_;
87 }
88
89 void
90 speech_destroy(struct speech *this_)
91 {
92 this_->meth.destroy(this_->priv);
93 attr_list_free(this_->attrs);
94 g_free(this_);
95 }
96
97 int
98 speech_say(struct speech *this_, const char *text)
99 {
100 debug_get_timestamp_millis(&global_last_spoken);
101 return (this_->meth.say)(this_->priv, text);
102 }
103
104 /**
105 * @brief Gets an attribute from a speech plugin
106 *
107 * @param this_ The speech plugin the attribute should be read from
108 * @param type The type of the attribute to be read
109 * @param attr Pointer to an attrib-structure where the attribute should be written to
110 * @param iter (NOT IMPLEMENTED) Used to iterate through all attributes of a type. Set this to NULL to get the first attribute, set this to an attr_iter to get the next attribute
111 * @return True if the attribute type was found, false if not
112 */
113
114 int
115 speech_get_attr(struct speech *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
116 {
117 return attr_generic_get_attr(this_->attrs, NULL, type, attr, iter);
118 }
119
120 /**
121 * @brief Tries to estimate how long it will take to speak a certain string
122 *
123 * This function tries to estimate how long it will take to speak a certain string
124 * passed in str. It relies on the "characters per second"-value passed from the
125 * configuration.
126 *
127 * @param this_ The speech whose speed should be used
128 * @param str The string that should be estimated
129 * @return Time in tenth of seconds or -1 on error
130 */
131 int
132 speech_estimate_duration(struct speech *this_, char *str)
133 {
134 int count;
135 struct attr cps_attr;
136
137 count = strlen(str);
138
139 if (!speech_get_attr(this_, attr_cps, &cps_attr, NULL))
140 {
141 // just assume 15 char/sec spoken speed
142 // dbg(0 , "SP_CPS:(default)%d\n", 15);
143 return (count * 10) / 15;
144 }
145
146 // dbg(0 , "SP_CPS:%d\n", cps_attr.u.num);
147 return (count * 10) / cps_attr.u.num;
148 }
149
150 /**
151 * @brief Sets an attribute from an speech plugin
152 *
153 * This sets an attribute of a speech plugin, overwriting an attribute of the same type if it
154 * already exists. This function also calls all the callbacks that are registred
155 * to be called when attributes change.
156 *
157 * @param this_ The speech plugin to set the attribute of
158 * @param attr The attribute to set
159 * @return True if the attr could be set, false otherwise
160 */
161
162 int
163 speech_set_attr(struct speech *this_, struct attr *attr)
164 {
165 this_->attrs=attr_generic_set_attr(this_->attrs, attr);
166 //callback_list_call_attr_2(this_->attr_cbl, attr->type, this_, attr);
167 return 1;
168 }

   
Visit the ZANavi Wiki