diff --git a/fhem/CHANGED b/fhem/CHANGED
index 09a87b7a5..9331cc669 100644
--- a/fhem/CHANGED
+++ b/fhem/CHANGED
@@ -1,5 +1,6 @@
# 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: 98_Text2Speech.pm: some Improvements by Mirko
- change: 73_GardenaSmartBridge: Change part of code for new API
- bugfix: 47_OBIS: fixed bug with 64 bit integer numbers
- change: 46_TeslaPowerwall2AC: Code rewrite for new Auth API and
diff --git a/fhem/FHEM/98_Text2Speech.pm b/fhem/FHEM/98_Text2Speech.pm
index 81251c32a..5cfbd281b 100644
--- a/fhem/FHEM/98_Text2Speech.pm
+++ b/fhem/FHEM/98_Text2Speech.pm
@@ -15,8 +15,6 @@
# ALL ALL = NOPASSWD: /usr/bin/mplayer
##############################################
-# VoiceRSS: http://www.voicerss.org/api/documentation.aspx
-
package main;
use strict;
use warnings;
@@ -240,37 +238,37 @@ sub Text2Speech_loadmodules($$) {
require IO::File;
IO::File->import;
1;
- } or return "IO::File Module not installed, please install";
+ } or return "IO::File Module not installed. Please install.";
eval {
require Digest::MD5;
Digest::MD5->import;
1;
- } or return "Digest::MD5 Module not installed, please install";
+ } or return "Digest::MD5 Module not installed. Please install.";
eval {
require URI::Escape;
URI::Escape->import;
1;
- } or return "URI::Escape Module not installed, please install";
+ } or return "URI::Escape Module not installed. Please install.";
eval {
require Text::Iconv;
Text::Iconv->import;
1;
- } or return "Text::Iconv Module not installed, please install";
+ } or return "Text::Iconv Module not installed. Please install.";
eval {
require Encode::Guess;
Encode::Guess->import;
1;
- } or return "Encode::Guess Module not installed, please install";
+ } or return "Encode::Guess Module not installed. Please install.";
eval {
require MP3::Info;
MP3::Info->import;
1;
- } or return "MP3::Info Module not installed, please install";
+ } or return "MP3::Info Module not installed. Please install.";
if ($TTS_Ressource eq "Amazon-Polly") {
# Module werden nur benötigt mit der Polly Engine
@@ -278,7 +276,7 @@ sub Text2Speech_loadmodules($$) {
require Paws::Polly;
Paws::Polly->import;
1;
- } or return "Paws Module not installed. Please install, goto https://metacpan.org/source/JLMARTIN/Paws-0.39";
+ } or return "Paws Module not installed. Please install.";
eval {
require File::HomeDir;
@@ -522,6 +520,8 @@ sub Text2Speech_Set($@)
if($cmd ne "tts") {
return "$cmd needs $sets{$cmd} parameter(s)" if(@a-$sets{$cmd} != 0);
+ } else {
+ return "$cmd needs text parameter" if(@a-$sets{$cmd} < 0);
}
# Abbruch falls Disabled
@@ -585,6 +585,18 @@ sub Text2Speech_PrepareSpeech($$) {
my $TTS_ForceSplit = 0;
my $TTS_AddDelimiter;
+ # Cleanup string
+ $hash->{helper}{TTS_PlayerOptions} = "";
+ while ($t =~ s/^ //isg) {};
+ $t =~ s/^'(.*)'$/$1/;
+ $t =~ s/^"(.*)"$/$1/;
+
+ # Check text for command string
+ if ($t =~ /^\[(.*?)\](.*?)$/) {
+ ($hash->{helper}{TTS_PlayerOptions}, $t) = ($1, $2);
+ while ($t =~ s/^ //isg) {};
+ }
+
if($TTS_Delimiter && $TTS_Delimiter =~ m/^[+-]a[lfn]/i) {
$TTS_ForceSplit = 1 if(substr($TTS_Delimiter,0,1) eq "+");
$TTS_ForceSplit = 0 if(substr($TTS_Delimiter,0,1) eq "-");
@@ -655,7 +667,7 @@ sub Text2Speech_PrepareSpeech($$) {
for(my $j=0; $j<(@FileTplPc); $j++) {
$text[$i] =~ s/:$FileTplPc[$j]:/$cutter$FileTplPc[$j]$cutter/g;
}
- @text = Text2Speech_SplitString(\@text, 0, $cutter, 1, "");
+ @text = Text2Speech_SplitString(\@text, 0, $cutter, 1, "");
}
Log3 $hash, 4, "$me: MaxChar = $ttsMaxChar{$TTS_Ressource}, Delimiter = $TTS_Delimiter, ForceSplit = $TTS_ForceSplit, AddDelimiter = $TTS_AddDelimiter";
@@ -669,23 +681,23 @@ sub Text2Speech_PrepareSpeech($$) {
@text = Text2Speech_SplitString(\@text, $ttsMaxChar{$TTS_Ressource}, "\\bund\\b", 0, "af");
@text = Text2Speech_SplitString(\@text, $ttsMaxChar{$TTS_Ressource}, " ", 0, "");
- Log3 $hash, 4, "$me: Auflistung der Textbausteine nach Aufbereitung:";
+ Log3 $hash, 4, "$me: Auflistung der Textbausteine nach Aufbereitung:";
for(my $i=0; $i<(@text); $i++) {
# entferne führende und abschließende Leerzeichen aus jedem Textbaustein
- $text[$i] =~ s/^\s+|\s+$//g;
+ $text[$i] =~ s/^\s+|\s+$//g;
for(my $j=0; $j<(@FileTpl); $j++) {
# ersetze die FileTemplates mit den echten MP3-Files
@FileTplPc = split(/:/, $FileTpl[$j]);
$text[$i] = $TTS_FileTemplateDir ."/". $FileTplPc[1] if($text[$i] eq $FileTplPc[0]);
}
- Log3 $hash, 4, "$me: $i => ".$text[$i];
+ Log3 $hash, 4, "$me: $i => ".$text[$i];
}
push( @{$hash->{helper}{Text2Speech}}, @text );
}
#####################################
-# param1: array : Text 2 Speech
+# param1: array : Text 2 Speech
# param2: string: MaxChar
# param3: string: Delimiter
# param4: int : 1 -> es wird am Delimiter gesplittet
@@ -694,7 +706,7 @@ sub Text2Speech_PrepareSpeech($$) {
#
# Splittet die Texte aus $hash->{helper}->{Text2Speech} anhand des
# Delimiters, wenn die Stringlänge MaxChars übersteigt.
-# Ist "AddDelimiter" angegeben, so wird der Delimiter an den
+# Ist "AddDelimiter" angegeben, so wird der Delimiter an den
# String wieder angefügt
#####################################
sub Text2Speech_SplitString($$$$$){
@@ -748,7 +760,7 @@ sub Text2Speech_SplitString($$$$$){
#####################################
# param1: hash : Hash
# param2: string: Datei
-#
+#
# Erstellt den Commandstring für den Systemaufruf
#####################################
sub Text2Speech_BuildMplayerCmdString($$) {
@@ -760,7 +772,7 @@ sub Text2Speech_BuildMplayerCmdString($$) {
my $verbose = AttrVal($hash->{NAME}, "verbose", 3);
if($hash->{VOLUME}) { # per: set
- This module converts any text into speech with serveral possible providers. The Device can be defined as locally
- or remote device.
+ This module converts any text into speech with several possible providers. The Device can be defined as locally
+ or remote instance.
Special AlsaDevice: default
Example:
+ Example:
- Das Modul wandelt Text mittels verschiedener Provider/Ressourcen in Sprache um. Dabei kann das Device als
- Remote, Lokales Device oder als Server konfiguriert werden.
+ Das Modul wandelt Text mittels verschiedener Provider/Ressourcen in Sprache um. Dabei kann das Device als
+ Remote, Lokales Device oder als Server konfiguriert werden.
Special AlsaDevice: default
Beispiel:
Beispiel:
Beispiel:Text2Speech
+Text2Speech
Define
Local :
define <name> Text2Speech <alsadevice>
- Remote: define <name> Text2Speech <host>[:<portnr>][:SSL] [portpassword]
+ Remote: define <name> Text2Speech <host>[:<portnr>][:SSL] [portpassword]
+ Server: define <name> Text2Speech none
- The output will be send to any connected audiodevice. For example external speakers connected per jack
- or with bluetooth speakers - connected per bluetooth dongle. Its important to install mplayer.
+ The output will be sent to any connected audio device. For example speakers connected per jack,
+ network, WiFI or Bluetooth. Playback can be done using MPlayer or any other application.
+
+ Mplayer installation under Debian/Ubuntu/Raspbian:
apt-get install mplayer
- The given alsadevice has to be configured in /etc/asound.conf
+ The given alsa device has to be configured in /etc/asound.conf
- The internal mplayer command will be without any audio directive if the given alsadevice is default.
- In this case mplayer is using the standard audiodevice.
+ The internal Mplayer command will be without any audio directive if the given alsa device is default.
+ In this case Mplayer is using the standard audio device.
@@ -1252,7 +1270,7 @@ sub Text2Speech_WriteStats($$$$){
- This module can configured as remote-device for client-server Environments. The Client has to be configured
+ This module can be configured as remote-device for client-server environments. The Client has to be configured
as local device.
-Set
+Set
Notice: the Name of the locally instance has to be the same!
@@ -1273,63 +1291,68 @@ sub Text2Speech_WriteStats($$$$){
- In case of an usage of an Server, only the mp3 file will be generated.It makes no sence to use the attribute TTS_speakAsFastAsPossible.
- Its recommend, to use the attribute TTS_useMP3Wrap. Otherwise only the last audiobrick will be shown is reading lastFilename.
+ In case of an usage as a server, only the mp3 file will be generated and displayed as lastFilename reading. It makes no sense to use the attribute TTS_speakAsFastAsPossible here.
+ Its recommend, to use the attribute TTS_useMP3Wrap. Otherwise only the last audiobrick will be shown in reading lastFilename.
+
+ define MyTTS Text2Speech none
+
- Giving a text to translate into audio. You play set mp3-files directly. In this case you have to enclosure them with a single colon before and after the declaration.
- The files must save under the directory of given TTS_FileTemplateDir.
- Please note: The text doesn´t have any colons itself.
+ Definition of text for voice output. To output mp3 files directly, they must be specified with
+ leading and closing colons. Therefore, the text itself must not contain any double punctuation.
+ The mp3 files must be stored in the TTS_FileTemplateDir directory.
+ SSML can be used for the Amazon Polly language engine. See examples.
+
Setting up the volume audio response.
Notice: Only available in locally instances!
+
-Get
-N/A
+Get
+N/A
Attributes
- optional: By using the google engine, its not possible to convert more than 100 characters in a single audio brick.
- With a Delimiter the audio brick will be split at this character. A Delimiter must be a single character.!
- By default, ech audio brick will be split at sentence end. Is a single sentence longer than 100 characters,
+ Optional: By using the Google engine, its not possible to convert more than 100 characters in a single audio brick.
+ With a delimiter the audio brick will be split at this character. A delimiter must be a single character!
+ By default, each audio brick will be split at sentence end. Is a single sentence longer than 100 characters,
the sentence will be split additionally at comma, semicolon and the word and.
Notice: Only available in locally instances with Google engine!
-
- optional: Selection of the Translator Engine
+ Optional: Selection of the Translator Engine
Notice: Only available in locally instances!
- Using the Google Engine. It´s nessessary to have internet access. This engine is the recommend engine
- because the quality is fantastic. This engine is using by default.
+ Google Engine. Prerequisite: Active Internet connection
+ This engine is recommended for its quality and is used by default.
- Using the VoiceRSS Engine. Its a free engine till 350 requests per day. If you need more, you have to pay.
- It´s nessessary to have internet access. This engine is the 2nd recommend engine
- because the quality is also fantastic. To use this engine you need an APIKey (see TTS_APIKey)
+ VoiceRSS Engine. Prerequisite: Active Internet connection
+ Free of charge up to 350 requests per day. If you need more, you have to pay.
+ This engine is also recommended due to its quality. To use this engine, you need an APIKey (see TTS_APIKey)
- Using the ESpeak Engine. Installation Espeak and lame is required.
- apt-get install espeak lame
+ eSpeak Engine. Prerequisite: Installation of Espeak and lame
+ eSpeak is an open source software speech synthesizer for English and other languages.
- Using the SVOX-Pico TTS-Engine (from the AOSP).
- Installation of the engine and lame
is required:
+ SVOX-Pico TTS-Engine (from the AOSP). Prerequisite: Installation of SVOX-Pico and lame
sudo apt-get install libttspico-utils lame
On ARM/Raspbian the package libttspico-utils
,
so you may have to compile it yourself or use the precompiled package from this guide, in short:
@@ -1339,8 +1362,8 @@ sub Text2Speech_WriteStats($$$$){
sudo dpkg --install pico2wave.deb
- Using the Amazon Polly engine, the same as Amazon Alexa.
- The perl package Paws is required. An AWS Access and Polly Aws User is required too
+ Amazon Polly Engine. Prerequisite: Active Internet connection, Perl package Paws
+ Amazon service that turns text into lifelike speech. An AWS Access and Polly Aws User is required.
cpan paws
The credentials to your AWS Polly are expected at ~/.aws/credentials
[default]
@@ -1356,52 +1379,67 @@ sub Text2Speech_WriteStats($$$$){
- if you want another engine and speech of default languages, you can insert this here.
- The definition is dependent of used engine. This attribute overrides an TTS_Language attribute.
- Please refer the specific API reference.
+ If you want another engine and speech of default languages, you can insert this here.
+ The definition depends on the used engine. This attribute overrides an TTS_Language attribute.
+ Please refer to the specific API reference.
- An APIKey its needed if you want to use VoiceRSS. You have to register at the following page:
- http://www.voicerss.org/registration.aspx
- After this, you will get your personal APIKey.
+ An APIKey is needed if you want to use VoiceRSS. You have to register at the following page:
+ http://www.voicerss.org/registration.aspx
- Actual without any usage. Needed in case if a TTS Engine need an username and an apikey for each request.
+ Actual without any usage. Needed in case if a TTS Engine needs a username and an APIKey for a request.
- optional: The downloaded Goole audio bricks are saved in this folder for reusing.
- No automatically implemented deleting are available.
+ Optional: The downloaded Google audio bricks are saved in this folder.
+ No automatic delete/cleanup available.
Default: cache/
- Notice: Only available in locally instances!
+ Notice: Available on local instances only!
- optional: To become a liquid audio response its recommend to use the tool mp3wrap.
- Each downloaded audio bricks are concatinated to a single audio file to play with mplayer.
- Installtion of the mp3wrap source is required.
+ For best voice output, it is recommended that the individual downloads are combined into a single file.
+ Each downloaded audio bricks are concatinated to a single audio file to play with Mplayer.
+ Installtion of the mp3wrap package is required.
apt-get install mp3wrap
- Notice: Only available in locally instances!
+ Notice: Available on local instances only!
- optional: Setting up the Mplayer system call. The following example is default.
- Example: sudo /usr/bin/mplayer
+ Optional: Definition of the system call to Mplayer or a different tool.
+ If a tool other than Mplayer is used, the following templates apply:
+
+
+ {options} are provided inside the text in parentheses during the set command.
+ Used for example to set special parameters for each call separately
+ Example: set myTTS tts [192.168.0.1:7000] This is my text
+
+ Examples:
+ attr myTTS TTS_MplayerCall sudo /usr/bin/mplayer
+ attr myTTS TTS_MplayerCall AUDIODEV={device} play -q -v {volume} {file}
+ attr myTTS TTS_MplayerCall player {file} {options}
+
Optional: Definition of one mp3-file to append each time of audio response.
- Using of Mp3Wrap is required. The audio bricks has to be downloaded before into CacheFileDir.
+ Mp3Wrap is required. The audio chunks must be downloaded to the CacheFileDir beforehand.
Example: silence.mp3
- Definition of mp3files with a custom templatedefinition. Separated by space.
- All templatedefinitions can used in audiobricks by tts.
- The definition must begin and end with e colon.
- The mp3files must saved in the given directory by TTS_FIleTemplateDir.
+ Definition of mp3files with a custom template definition. Separated by space.
+ All template definitions can be used in audiobricks by tts command.
+ The definition must begin and end with a colon.
+ The mp3files must be saved in TTS_FIleTemplateDir.
attr myTTS TTS_FileMapping ring:ringtone.mp3 beep:MyBeep.mp3
set MyTTS tts Attention: This is my ringtone :ring: Its loud?
cache/templates
+ Basic volume increase
+ Default: 110
+ attr myTTS TTS_VolumeAdjust 400
+
If set to 1, it prevents logging statistics to DbLog Devices, default is 0
- But please notice: this looging is important to able to delete longer unused cachefiles. If you disable this
- please take care to cleanup your cachedirectory by yourself.
+ Note: This logging is important to be able to delete cache files that have not been used for a longer period of time.
+ If you disable this, you will have to clean your cache directory manually.
- Trying to get an speach as fast as possible. In case of not present audiobricks, you can hear a short break.
- The audiobrick will be download at this time. In case of an presentation of all audiobricks at local cache,
- this attribute has no impact.
- Attribute only valid in case of an local or server instance.
+ Trying to get a speech as fast as possible. In case of not present audio bricks, you can
+ hear a short break as the audio brick will be downloaded at this time.
+ In case of a presentation of all audio bricks at local cache, this attribute has no impact.
+ Attribute is only valid on local or server instances.
+
+ Definition of a fixed file name as mp3 output. The attribute is only relevant in conjunction with TTS_UseMP3Wrap.
+ If a file name is specified, then TTS_CacheFileDir is also taken into account.
+ attr myTTS TTS_OutputFile output.mp3
+ attr myTTS TTS_OutputFile /media/miniDLNA/output.mp3
- If this attribute is activated, the soundoutput will be disabled.
+ If this attribute is activated, the sound output will be disabled.
Possible values: 0 => not disabled , 1 => disabled
- Default Value is 0 (not disabled)
+ Default Value is 0 (not disabled)
+
4: each step will be logged
- 5: Additionally the individual debug informations from mplayer and mp3wrap will be logged
+ 5: Additionally the individual debug information from Mplayer and mp3wrap will be logged
-Beispiele
+Examples
+
=end html
=begin html_DE
-define TTS_EG_WZ Text2Speech hw=/dev/snd/controlC3
+ attr TTS_EG_WZ TTS_Language English
+ attr TTS_EG_WZ TTS_Ressource Amazon-Polly
+ attr TTS_EG_WZ TTS_UseMP3Wrap 1
+ set MyTTS tts <speak>Mary had a little lamb.</speak>
+
define MyTTS Text2Speech hw=0.0
- set MyTTS tts Die Alarmanlage ist bereit.
+ set MyTTS tts The alarm system is ready.
set MyTTS tts :beep.mp3:
- set MyTTS tts :mytemplates/alarm.mp3:Die Alarmanlage ist bereit.:ring.mp3:
+ set MyTTS tts :mytemplates/alarm.mp3:The alarm system is ready.:ring.mp3:
Text2Speech
+Text2Speech
Define
Local :
define <name> Text2Speech <alsadevice>
- Remote: define <name> Text2Speech <host>[:<portnr>][:SSL] [portpassword]
+ Remote: define <name> Text2Speech <host>[:<portnr>][:SSL] [portpassword]
Server : define <name> Text2Speech none
- Die Ausgabe erfolgt auf angeschlossenen Audiodevices, zb. Lautsprecher direkt am Gerät oder per
- Bluetooth-Lautsprecher per Mplayer. Dazu ist Mplayer zu installieren.
+ Die Ausgabe wird an jedes angeschlossene Audiogerät gesendet. Zum Beispiel an einen lokalen Lautsprecher oder an
+ entfernte Geräte via Netzwerk, WiFI oder Bluetooth. Die Wiedergabe kann über MPlayer oder jede andere
+ Anwendung erfolgen.
+
+ Mplayer-Installation unter Debian/Ubuntu/Raspbian:
apt-get install mplayer
- Das angegebene Alsadevice ist in der /etc/asound.conf
zu konfigurieren.
+ Das angegebene Alsa-Device ist in der /etc/asound.conf
zu konfigurieren.
- Ist als Alsa-Device default angegeben, so wird mplayer ohne eine Audiodevice Angabe aufgerufen.
- Dementsprechend verwendet mplayer das Standard Audio Ausgabedevice.
+ Ist als Alsa-Device default angegeben, so wird Mplayer ohne eine Audiodevice-Angabe aufgerufen.
+ Dementsprechend verwendet Mplayer dann das Standard-Audio Ausgabedevice.
@@ -1489,102 +1549,103 @@ sub Text2Speech_WriteStats($$$$){
- Das Modul ist Client-Server fäas bedeutet, das auf der Haupt-FHEM Installation eine Text2Speech-Instanz
- als Remote definiert wird. Auf dem Client wird Text2Speech als Local definiert. Die Sprachausgabe erfolgt auf
+ Das Modul ist Client-Server fäas bedeutet, das auf der Haupt-FHEM Installation eine Text2Speech-Instanz
+ als Remote definiert wird. Auf dem Client wird Text2Speech als Local definiert. Die Sprachausgabe erfolgt auf
der lokalen Instanz.
- Zu beachten ist, das die Text2Speech Instanz (Definition als local Device) auf dem Zieldevice identisch benannt ist.
+ Zu beachten ist, dass die Text2Speech Instanz (Definition als Local-Device) auf dem Zieldevice identisch benannt ist.
define MyTTS Text2Speech 192.168.178.10:7072 fhempasswd
define MyTTS Text2Speech 192.168.178.10
- Im Falle der Verwendung als Server, wird nur die MP3 Datei erstellt und als Reading lastFilename dargestellt. Es macht keinen Sinn
- hier das Attribut TTS_speakAsFastAsPossible zu verwenden. Die Verwendung des Attributes TTS_useMP3Wrap wird dringend empfohlen.
+ Im Falle der Verwendung als Server wird nur die MP3-Datei erstellt und als Reading lastFilename dargestellt.
+ Es ergibt keinen Sinn hier das Attribut TTS_speakAsFastAsPossible zu verwenden.
+ Die Verwendung des Attributs TTS_useMP3Wrap wird dringend empfohlen.
Ansonsten wird hier nur der letzte Teiltext als mp3 Datei im Reading dargestellt.
define MyTTS Text2Speech none
-
attr myTTS TTS_Delimiter -al.
- apt-get install espeak lame
+ ESpeak Sprachengine. Voraussetzung: Installation von Espeak und lamelame
müssen installiert sein:sudo apt-get install libttspico-utils lame
libttspico-utils
leider nicht verfügbar,sudo dpkg --install pico2wave.deb
cpan paws
[default]
@@ -1608,12 +1669,12 @@ sub Text2Speech_WriteStats($$$$){
apt-get install mp3wrap
attr myTTS TTS_MplayerCall sudo /usr/bin/mplayer
- attr myTTS TTS_MplayerCall AUDIODEV={device} play -q -v {volume} {file}
+ {options} werden als Text in Klammern bei der Ausführung von set gesetzt, um beispielsweise spezielle
+ Parameter für jeden Aufruf separat zu setzenset myTTS tts [192.168.0.1:7000] Das ist mein Text
attr myTTS TTS_MplayerCall sudo /usr/bin/mplayer
attr myTTS TTS_MplayerCall AUDIODEV={device} play -q -v {volume} {file}
attr myTTS TTS_MplayerCall player {file} {options}
silence.mp3
attr myTTS TTS_FileMapping ring:ringtone.mp3 beep:MyBeep.mp3
attr myTTS TTS_OutputFile output.mp3
attr myTTS TTS_OutputFile /media/miniDLNA/output.mp3
define TTS_EG_WZ Text2Speech hw=/dev/snd/controlC3
attr TTS_EG_WZ TTS_Language Deutsch