Fix:core:Modified sunrise/set calculation coefficients
[navit-package] / navit / speech.c
index e84b0f8..c3e77f0 100644 (file)
@@ -35,7 +35,7 @@ struct speech *
 speech_new(struct attr *parent, struct attr **attrs) 
 {
        struct speech *this_;
-       struct speech_priv *(*speech_new)(struct speech_methods *meth, struct attr **attrs);
+       struct speech_priv *(*speech_new)(struct speech_methods *meth, struct attr **attrs, struct attr *parent);
        struct attr *attr;
 
     attr=attr_search(attrs, NULL, attr_type);
@@ -51,7 +51,7 @@ speech_new(struct attr *parent, struct attr **attrs)
                 return NULL;
        }
        this_=g_new0(struct speech, 1);
-       this_->priv=speech_new(&this_->meth, attrs);
+       this_->priv=speech_new(&this_->meth, attrs, parent);
     this_->attrs=attr_list_dup(attrs);
        dbg(1, "say=%p\n", this_->meth.say);
        dbg(1,"priv=%p\n", this_->priv);
@@ -68,7 +68,6 @@ int
 speech_say(struct speech *this_, const char *text)
 {
        dbg(1, "this_=%p text='%s' calling %p\n", this_, text, this_->meth.say);
-    dbg(0, "penispillen\n");
        return (this_->meth.say)(this_->priv, text);
 }
 
@@ -89,6 +88,32 @@ speech_get_attr(struct speech *this_, enum attr_type type, struct attr *attr, st
 }
 
 /**
+ * @brief Tries to estimate how long it will take to speak a certain string
+ *
+ * This function tries to estimate how long it will take to speak a certain string
+ * passed in str. It relies on the "characters per second"-value passed from the
+ * configuration.
+ *
+ * @param this_ The speech whose speed should be used
+ * @param str The string that should be estimated
+ * @return Time in tenth of seconds or -1 on error
+ */
+int
+speech_estimate_duration(struct speech *this_, char *str)
+{
+       int count;
+       struct attr cps_attr;
+   
+       if (!speech_get_attr(this_,attr_cps,&cps_attr,NULL)) {
+               return -1;
+       }
+
+       count = strlen(str);
+       
+       return (count * 10) / cps_attr.u.num;
+}
+
+/**
  * @brief Sets an attribute from an speech plugin
  *
  * This sets an attribute of a speech plugin, overwriting an attribute of the same type if it