From c5d6abbfc8ce1cd29104c6959b0de257e5b008f6 Mon Sep 17 00:00:00 2001
From: Beta-User <>
Date: Sat, 5 Mar 2022 10:29:47 +0000
Subject: [PATCH] 10_RHASSPY: restructured AMAD.* logic
git-svn-id: https://svn.fhem.de/fhem/trunk@25778 2b470e98-0d58-463d-a4d8-8e2adae1ed80
---
fhem/contrib/RHASSPY/10_RHASSPY.pm | 72 ++++++++++++++++--------------
1 file changed, 38 insertions(+), 34 deletions(-)
diff --git a/fhem/contrib/RHASSPY/10_RHASSPY.pm b/fhem/contrib/RHASSPY/10_RHASSPY.pm
index 13b66e564..92f7dc408 100644
--- a/fhem/contrib/RHASSPY/10_RHASSPY.pm
+++ b/fhem/contrib/RHASSPY/10_RHASSPY.pm
@@ -289,7 +289,7 @@ sub Initialize {
#$hash->{RenameFn} = \&Rename;
$hash->{SetFn} = \&Set;
$hash->{AttrFn} = \&Attr;
- $hash->{AttrList} = "IODev rhasspyIntents:textField-long rhasspyShortcuts:textField-long rhasspyTweaks:textField-long response:textField-long rhasspyHotwords:textField-long rhasspyMsgDialog:textField-long rhasspyTTS:textField-long rhasspySTT:textField-long forceNEXT:0,1 disable:0,1 disabledForIntervals languageFile " . $readingFnAttributes;
+ $hash->{AttrList} = "IODev rhasspyIntents:textField-long rhasspyShortcuts:textField-long rhasspyTweaks:textField-long response:textField-long rhasspyHotwords:textField-long rhasspyMsgDialog:textField-long rhasspySTT:textField-long forceNEXT:0,1 disable:0,1 disabledForIntervals languageFile " . $readingFnAttributes; #rhasspyTTS:textField-long
$hash->{Match} = q{.*};
$hash->{ParseFn} = \&Parse;
$hash->{NotifyFn} = \&Notify;
@@ -320,7 +320,7 @@ sub Define {
$hash->{defaultRoom} = $defaultRoom;
my $language = $h->{language} // shift @{$anon} // lc AttrVal('global','language','en');
- $hash->{MODULE_VERSION} = '0.5.18';
+ $hash->{MODULE_VERSION} = '0.5.19';
$hash->{baseUrl} = $Rhasspy;
initialize_Language($hash, $language) if !defined $hash->{LANGUAGE} || $hash->{LANGUAGE} ne $language;
$hash->{LANGUAGE} = $language;
@@ -378,7 +378,7 @@ sub firstInit {
&& InternalVal( InternalVal($name, 'IODev',undef)->{NAME}, 'IODev', 'none') eq 'MQTT2_CLIENT';
initialize_devicemap($hash);
initialize_msgDialog($hash);
- initialize_TTS($hash);
+ #initialize_TTS($hash);
initialize_STT($hash);
if ( 0 && $hash->{Babble} ) { #deactivate
InternalVal($hash->{Babble},'TYPE','none') eq 'Babble' ? $sets{Babble} = [qw( optionA optionB )]
@@ -1404,9 +1404,11 @@ sub initialize_STT {
}
}
$hash->{helper}->{STT}->{config}->{$keywd} = $values;
+ $hash->{helper}->{STT}->{config}->{AMADCommBridge} = 1;
+ disable_msgDialog( $hash, ReadingsVal($hash->{NAME}, 'enableMsgDialog', 1), 1 );
next;
}
-
+=pod
if ( $keywd =~ m{\AAMADCommBridge\z}xms ) {
for my $bridge (split m{,}, $values) {
if ( InternalVal($bridge,'TYPE','unknown') ne 'AMADCommBridge' ) {
@@ -1418,6 +1420,7 @@ sub initialize_STT {
disable_msgDialog( $hash, ReadingsVal($hash->{NAME}, 'enableMsgDialog', 1), 1 );
next;
}
+=cut
if ( $keywd =~ m{\AfilterFromBabble\z}xms ) {
if ( !defined $hash->{Babble} ) {
@@ -1427,6 +1430,15 @@ sub initialize_STT {
$hash->{helper}->{STT}->{config}->{$keywd} = _toregex($values);
next;
}
+
+ if ( $keywd =~ m{\b$hash->{helper}->{STT}->{config}->{allowed}(?:[\b:\s]|\Z)}xms ) {
+ my($unnamedParams, $namedParams) = parseParams($values);
+ #my $siteId = $namedParams->{siteId} // shift @{$unnamedParams }// $keywd;
+ $hash->{helper}->{STT}->{config}->{$keywd} = $namedParams;
+ #$hash->{helper}->{STT}->{config}->{$keywd}->{ttsCommand} //= 'set $DEVICE ttsMsg $message';
+ $hash->{helper}->{STT}->{config}->{wakeword}->{$namedParams->{wakeword}} = $keywd if defined $namedParams->{wakeword};
+ $sets{sayFinished} = [];
+ }
}
if ( !defined $hash->{helper}->{STT}->{config}->{allowed} ) {
@@ -2766,7 +2778,7 @@ sub ttsDialog_open {
customData => $device
};
- my $tout = $hash->{helper}->{TTS}->{config}->{$device}->{sessionTimeout} // $hash->{sessionTimeout};
+ my $tout = $hash->{helper}->{STT}->{config}->{$device}->{sessionTimeout} // $hash->{sessionTimeout};
setTtsDialogTimeout($hash, $sendData, $tout);
return ttsDialog_progress($hash, $device, $msgtext, $sendData);
}
@@ -2810,7 +2822,9 @@ sub ttsDialog_respond {
trim($message);
return if !$message; # empty?
- my $msgCommand = $hash->{helper}->{TTS}->{config}->{$device}->{ttsCommand} // return;
+ my $msgCommand = $hash->{helper}->{STT}->{config}->{$device}->{ttsCommand};
+ $msgCommand //= 'set $DEVICE ttsMsg $message' if InternalVal($device, 'TYPE', '') eq 'AMADDevice';
+ return if !$msgCommand;
my %specials = (
'$DEVICE' => $device,
'$message' => $message,
@@ -2819,7 +2833,7 @@ sub ttsDialog_respond {
$msgCommand = EvalSpecials($msgCommand, %specials);
AnalyzeCommandChain($hash, $msgCommand);
if ( $keepopen ) {
- my $tout = $hash->{helper}->{TTS}->{config}->{$device}->{sessionTimeout} // $hash->{sessionTimeout};
+ my $tout = $hash->{helper}->{STT}->{config}->{$device}->{sessionTimeout} // $hash->{sessionTimeout};
resetRegIntTimer( $device, time + $tout, \&RHASSPY_ttsDialogTimeout, $hash, 0);
readingsSingleUpdate($defs{$device}, 'rhasspy_dialogue', 'open', 1);
} else {
@@ -2955,9 +2969,10 @@ sub analyzeMQTTmessage {
my $siteId = $data->{siteId};
if ( 0 && $siteId ) { #Beta-User: deactivated
my $device = ReadingsVal($hash->{NAME}, "siteId2ttsDevice_$siteId",undef);
- $device //= $hash->{helper}->{TTS}->{$siteId} if defined $hash->{helper}->{TTS} && defined $hash->{helper}->{TTS}->{$siteId};
+ #$device //= $hash->{helper}->{TTS}->{$siteId} if defined $hash->{helper}->{TTS} && defined $hash->{helper}->{TTS}->{$siteId};
+ $device //= $hash->{helper}->{STT}->{config}->{wakeword}->{$hotword} if defined $hash->{helper}->{STT} && defined $hash->{helper}->{STT}->{config} && defined $hash->{helper}->{STT}->{config}->{wakeword};
if ($device) {
- analyzeAndRunCmd($hash, $device, "set $device activateVoiceInput");
+ AnalyzeCommand( $hash, "set $device activateVoiceInput" );
push @updatedList, $device;
}
}
@@ -3071,17 +3086,11 @@ sub respond {
&& defined $hash->{helper}->{msgDialog}->{$identity} ){
Log3($hash, 5, "respond deviated to msgDialog_respond for $identity.");
return msgDialog_respond($hash, $identity, $response);
- } elsif (defined $hash->{helper}->{TTS}
- && defined $hash->{helper}->{TTS}->{config}->{$identity} ) {
+ } elsif (defined $hash->{helper}->{STT}
+ && defined $hash->{helper}->{STT}->{config}->{$identity} ) {
Log3($hash, 5, "respond deviated to ttsDialog_respond for $identity.");
$hash->{helper}->{ttsDialog}->{$identity}->{data} = $data if $topic eq 'continueSession';
return ttsDialog_respond($hash,$identity,$response,$topic eq 'continueSession');
- } elsif (defined $hash->{helper}->{TTS}
- && defined $hash->{helper}->{TTS}->{$identity} ) {
- $identity = $hash->{helper}->{TTS}->{$identity};
- Log3($hash, 5, "respond deviated to ttsDialog_respond for $identity by siteId.");
- $hash->{helper}->{ttsDialog}->{$identity}->{data} = $data if $topic eq 'continueSession';
- return ttsDialog_respond($hash,$identity,$response,$topic eq 'continueSession');
}
IOWrite($hash, 'publish', qq{hermes/dialogueManager/$topic $json});
@@ -5631,36 +5640,31 @@ i="i am hungry" f="set Stove on" d="Stove" c="would you like roast pork"<
-
Remarks on rhasspySTT, rhasspyTTS and Babble:
+
Remarks on rhasspySTT and Babble:
Interaction with Babble and AMAD.*-Devices is not approved to be propperly working yet. Further tests
may be needed and functionality may be subject to changes!
Optionally, you may want not to use the internal Rhasspy speach-to-text engine provided by Rhasspy (for one or several siteId's), but provide simple text to be forwarded to Rhasspy for intent recognition. Atm. only "AMAD" is supported for this feature, and most likely you also want to set values to rhasspyTTS as well. For generic "msg" (and text messenger) support see rhasspyMsgDialog
Note: You will have to (de-) activate these parts of the Rhasspy ecosystem for the respective satellites manually!
Optionally, you may want not to use the internal Rhasspy speach-to-text engine provided by Rhasspy (for one or several siteId's), but provide simple text to be forwarded to Rhasspy for intent recognition. Atm. only "AMAD" is supported for this feature. For generic "msg" (and text messenger) support see rhasspyMsgDialog
Note: You will have to (de-) activate these parts of the Rhasspy ecosystem for the respective satellites manually!
Babble_DoIt()
function.filterFromBabble=tell rhasspy
- AMADCommBridge=AMADBridge
- allowed=AMADDev_A
In addition to rhasspySTT, this attributes adds some options to manipulate the text-to-speech processing. Any AMADDevice to be adressed for own TTS processing has to be listed here with it's link to it's siteId (development remark: this is missleading atm!). If RHASSPY detects a link between a siteId and an AMADDevice type FHEM device, it will not forward any text to be spoken to Rhasspy but use other synthetisation methods instead (defaulting to set <AMADDevice> ttsMsg $message
).
- Example:
-
AMADDev_A=siteId=android_livingroom ttsCommand={fhem("set $DEVICE ttsMsg $message")}
Notes:
-
allowed=AMADDev_A
+ filterFromBabble=tell rhasspy
+ <AMAD-device>=wakeword=alexa sessionTimeout=20