From bdebf72d65ac825da3d7c14750d7b7973e0efc91 Mon Sep 17 00:00:00 2001
From: Tobias <>
Date: Tue, 20 Dec 2016 08:11:33 +0000
Subject: [PATCH] 98_Text2Speech.pm: (thanks to Ellert) *
attribute 'playing' will updated only in local mode * in
case of abort of blockingfunction, 'playing' is set to 0 *
Remote mode: if modul 'presence' is in use and TTS-remote host
is defined, this info will be used to prevent an
waiting state for unavaliable remote Host * new Attribute:
TTS_noStatistcsLog to disable logging of usage of
cachefiles, please read Commandref carfully!
git-svn-id: https://svn.fhem.de/fhem/trunk@12844 2b470e98-0d58-463d-a4d8-8e2adae1ed80
---
fhem/CHANGED | 10 ++++++-
fhem/FHEM/98_Text2Speech.pm | 59 ++++++++++++++++++++++++++++++-------
fhem/MAINTAINER.txt | 3 ++
3 files changed, 61 insertions(+), 11 deletions(-)
diff --git a/fhem/CHANGED b/fhem/CHANGED
index 19ccdc7cf..2677a5fd4 100644
--- a/fhem/CHANGED
+++ b/fhem/CHANGED
@@ -1,6 +1,14 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
# Do not insert empty lines here, update check depends on it.
- - bugfix 73_GasCalculator: Monthly reading and yearly reading name alingned
+ - update: 98_Text2Speech.pm: (thanks to Ellert)
+ * attribute 'playing' will updated only in local mode
+ * in case of abort of blockingfunction, 'playing' is set to 0
+ * Remote mode: if modul 'presence' is in use and TTS-remote
+ host is defined, this info will be used to prevent an
+ waiting state for unavaliable remote Host
+ * new Attribute: TTS_noStatistcsLog to disable logging of
+ usage of cachefiles, please read Commandref carfully!
+ - bugfix: 73_GasCalculator: Monthly reading and yearly reading name alingned
- feature: 98_TRAFFIC: reverse waypoints, integrated map for visualization
- update: 77_UWZ: New Version 1.4.7 added headlines for weblinks
- update: 73_NUKIBridge,74_NUKIDevice: New Version 0.4.0
diff --git a/fhem/FHEM/98_Text2Speech.pm b/fhem/FHEM/98_Text2Speech.pm
index 143ec8e3d..845345af8 100644
--- a/fhem/FHEM/98_Text2Speech.pm
+++ b/fhem/FHEM/98_Text2Speech.pm
@@ -160,7 +160,8 @@ sub Text2Speech_Initialize($)
" TTS_SentenceAppendix".
" TTS_FileMapping".
" TTS_FileTemplateDir".
- " TTS_VolumeAdjust".
+ " TTS_VolumeAdjust".
+ " TTS_noStatisticsLog:1,0".
" TTS_Language:".join(",", sort keys %{$language{"Google"}}).
" ".$readingFnAttributes;
}
@@ -377,9 +378,32 @@ sub Text2Speech_Write($$) {
#my $call = "set tts tts Das ist ein Test.";
my $call = "set $name $msg";
- Text2Speech_OpenDev($hash) if(!$hash->{TCPDev});
- #lets try again
- Text2Speech_OpenDev($hash) if(!$hash->{TCPDev});
+ #Prüfen ob PRESENCE vorhanden und present
+ my $isPresent = 0;
+ my $hasPRESENCE = 0;
+ my $devname="";
+ if ($hash->{MODE} eq "REMOTE") {
+ foreach $devname (devspec2array("TYPE=PRESENCE")) {
+ if (defined $defs{$devname}->{ADDRESS} && $dev) {
+ if ($dev =~ $defs{$devname}->{ADDRESS}) {
+ $hasPRESENCE = 1;
+ $isPresent = 1 if (ReadingsVal($devname,"presence","unknown") eq "present");
+ last;
+ }
+ }
+ }
+ }
+ if ($hasPRESENCE) {
+ Log3 $hash, 4, "Text2Speech($name): found PRESENCE Device $devname for host: $dev, it\'s state is: ".($isPresent ? "present" : "absent");
+ Text2Speech_OpenDev($hash) if(!$hash->{TCPDev} && $isPresent);
+ #lets try again
+ Text2Speech_OpenDev($hash) if(!$hash->{TCPDev} && $isPresent);
+ } else {
+ Log3 $hash, 4, "Text2Speech($name): no proper PRESENCE Device for host: $dev";
+ Text2Speech_OpenDev($hash) if(!$hash->{TCPDev});
+ #lets try again
+ Text2Speech_OpenDev($hash) if(!$hash->{TCPDev});
+ }
if($hash->{TCPDev}) {
Log3 $hash, 4, "Text2Speech: Write remote message to $dev: $call";
@@ -421,10 +445,10 @@ sub Text2Speech_Set($@)
# Abbruch falls Disabled
return undef if(AttrVal($hash->{NAME}, "disable", "0") eq "1");
-
if($cmd eq "tts") {
- readingsSingleUpdate($hash, "playing", "1", 1);
+
if($hash->{MODE} eq "DIRECT") {
+ readingsSingleUpdate($hash, "playing", "1", 1);
Text2Speech_PrepareSpeech($hash, join(" ", @a));
$hash->{helper}{RUNNING_PID} = BlockingCall("Text2Speech_DoIt", $hash, "Text2Speech_Done", $TTS_TimeOut, "Text2Speech_AbortFn", $hash) unless(exists($hash->{helper}{RUNNING_PID}));
} elsif ($hash->{MODE} eq "REMOTE") {
@@ -433,7 +457,7 @@ sub Text2Speech_Set($@)
} elsif($cmd eq "volume") {
my $vol = join(" ", @a);
return "volume level expects 0..100 percent" if($vol !~ m/^([0-9]{1,3})$/ or $vol > 100);
-
+
if($hash->{MODE} eq "DIRECT") {
$hash->{VOLUME} = $vol if($vol <= 100);
delete($hash->{VOLUME}) if($vol > 100);
@@ -795,7 +819,7 @@ sub Text2Speech_DoIt($) {
if(! -e $Mp3WrapFile) {
$cmd = "mp3wrap " .$TTS_CacheFileDir. "/" .$Mp3WrapPrefix. ".mp3 " .join(" ", @Mp3WrapFiles);
- $cmd .= " >/dev/null" if($verbose < 5);;
+ $cmd .= " >/dev/null" if($verbose < 5);
Log3 $hash->{NAME}, 4, "Text2Speech: " .$cmd;
system($cmd);
@@ -876,7 +900,7 @@ sub Text2Speech_Done($) {
for(my $i=0; $i<$tts_done; $i++) {
push(@text, $hash->{helper}{Text2Speech}[$i]);
}
- Text2Speech_WriteStats($hash, 1, $filename, join(" ", @text));
+ Text2Speech_WriteStats($hash, 1, $filename, join(" ", @text)) if (AttrVal($hash->{NAME},"TTS_noStatisticsLog", "1"));
}
delete($hash->{helper}{RUNNING_PID});
@@ -896,6 +920,7 @@ sub Text2Speech_AbortFn($) {
delete($hash->{helper}{RUNNING_PID});
Log3 $hash->{NAME}, 2, "Text2Speech: BlockingCall for ".$hash->{NAME}." was aborted";
+ readingsSingleUpdate($hash, "playing", "0", 1);
}
#####################################
@@ -922,7 +947,7 @@ sub Text2Speech_WriteStats($$$$){
}
return undef if($defs{$DbLogDev}{STATE} !~ m/(active|connected)/); # muss active sein!
- # den letzten Value von "Usage" ermitteln um dann die Staistik um 1 zu erhoehen.
+ # den letzten Value von "Usage" ermitteln um dann die Statistik um 1 zu erhoehen.
my @LastValue = DbLog_Get($defs{$DbLogDev}, "", "current", "array", "-", "-", $hash->{NAME} ."|". $file.":Usage");
my $NewValue = 1;
$NewValue = $LastValue[0]{value} + 1 if($LastValue[0]);
@@ -990,6 +1015,7 @@ sub Text2Speech_WriteStats($$$$){
define MyTTS Text2Speech 192.168.178.10:7072 fhempasswd
define MyTTS Text2Speech 192.168.178.10
cache/templates
+ define MyTTS Text2Speech 192.168.178.10:7072 fhempasswd
define MyTTS Text2Speech 192.168.178.10
+ Wenn ein PRESENCE Gerät die Host IP-Adresse abfragt, wird die blockierende interne Prüfung auf Erreichbarkeit umgangen und das PRESENCE Gerät genutzt.
attr myTTS TTS_VolumeAdjust 400