Text-to-Speech module for MagicMirror² with Google Cloud TTS API.
1.1.1
- 2023.03.071.1.0
- 2021.10.03moment
dependency.This module works on Background, so there is no screenshot.
This module gives "voice" to MagicMirror²
MMM-TelegramBot
command /tts
cd ~/MagicMirror/modules
git clone https://github.com/MMRIZE/MMM-GoogleTTS
cd MMM-GoogleTTS
npm install
./node_modules/.bin/electron-rebuild
cp api_count.json.temp api_count.json
Select or create a Cloud Platform project.
Enable billing for your project.
WaveNet
voice) characters could be used per month.Enable the Google Cloud Text-to-Speech API.
Set up authentication with a service account so you can access the API from your device.
Rename downloaded file to credentials.json
and copy it to MMM-GoogleTTS
directory
{
module: "MMM-GoogleTTS", // no `position` is needed.
config: {}
},
{
module: "MMM-GoogleTTS", // no `position` is needed.
config: {
welcome: ["May the force be with you", "Live long and prosper"],
// String or Array of String or callback function to return String or Array. To disable this feature, set to null.
/* Other example
welcome: null,
welcome: "Hello",
welcome: ()=> {
var d = Math.floor((Math.random() * 10) + 1)
return "Today's Lucky number is" + d
},
*/
dailyCharLimit: 129000,
// 4 Million divide by 30. I think it's enough for daily usage. If you have a will to pay, you can expand this value as your wish. But free usage will be enough.
// Warning. When you use WaveNet voice, your free quota will be `1 Million per month` not `4 Million`.
sourceType: "text",
// "text" or "ssml".
voiceName: "en-US-Standard-C",
// If exists. e.g)"en-US-Standard-C". You can select specific voice name when there are many voices with same languageCode and gender.
// voiceName should be matched with languageCode and ssmlGender
languageCode: "en-US",
ssmlGender: "FEMALE",
// "MALE", "FEMALE", "NEUTRAL" or "SSML_VOICE_GENDER_UNSPECIFIED"
// supported voices, languages and gender;
// https://cloud.google.com/text-to-speech/docs/voices
playCommand: "aplay %OUTPUTFILE%",
// aplay, mpg321, afplay, as your wish....
// sometimes you should give more options to play correctly.
// e.g) "aplay -D plughw:1,0 $OUTPUTFILE%"
audioEncoding: "LINEAR16",
// LINEAR16 (.wav) or MP3 (.mp3) for playCommand. You don't need to modify this when you use `aplay`
notificationTrigger: {
"TEST_TTS" : "Test TTS notification is coming",
"SHOW_ALERT" : (payload, sender) => {
return payload.message
},
},
// You can hook specific notification to speak something. String or callback function could be available.
// You don't need to modify belows;
notifications: {
TTS_SAY: "TTS_SAY",
TTS_SAY_STARTING: "TTS_SAY_STARTING",
TTS_SAY_ENDING: "TTS_SAY_ENDING",
TTS_SAY_ERROR: "TTS_SAY_ERROR"
},
credentialPath: "credentials.json",
}
},
You can hook specific notification to speak something with that notification. By example;
notificationTrigger: {
"TEST_TTS" : "Test TTS notification is coming",
"SHOW_ALERT" : (payload, sender) => {
return payload.message
},
},
TEST_TTS
notification is received, "Test TTS notification is coming" will be spoken.SHOW_ALERT
notification is received, payload.message
will be spoken. You can make Mirror to read ALERT
by its voice.With TTS_SAY
notification, Other module can order this module to speak
this.sendNotification("TTS_SAY", "May the Force be with you")
Or,
this.sendNotification("TTS_SAY", {
content: "Live long and prosper", //text to be spoken
//belows are optional
type: "text", // "text" or "ssml"
voiceName: "en-US-Standard-B",
languageCode: "en-US",
ssmlGender: "FEMALE",
callback: (error)=> {
console.log("Message is spoken.")
}
})
/tts something
or /alert something
/tts Mom, I'm Tom, coming home now. I'm so hungry
Google Text-To-Speech SDK is limited free. 4 Millions characters could be used per month without charge. I think it’s quiet enough for usual usage. You can limit daily usage by force with configuration to avoid charging. (But it’s your responsibility)
If you are using another module or program which use speaker, use this carefully. Occupation collision could happen.