Skip to content

Commit

Permalink
no message
Browse files Browse the repository at this point in the history
  • Loading branch information
Nall-chan committed May 26, 2023
1 parent ac58105 commit 7126ccb
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 61 deletions.
21 changes: 8 additions & 13 deletions .github/workflows/style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,14 @@ name: Check Style
on: [push, pull_request]

jobs:

style:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@master

- name: Only fetch Style PHP submodule
run: git submodule update --init -- .style

- name: Install latest PHP-CS-Fixer
run: wget https://cs.symfony.com/download/php-cs-fixer-v2.phar

- name: Run Checks
run: php php-cs-fixer-v2.phar fix --config=.style/.php_cs -v --dry-run --allow-risky=yes .
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
- name: Checkout module
uses: actions/checkout@master
- name: Check style
uses: Nall-chan/action-style@strict
18 changes: 6 additions & 12 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,12 @@ name: Run Tests
on: [push, pull_request]

jobs:

test:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
with:
submodules: true

- name: Install latest PHPUnit
run: wget https://phar.phpunit.de/phpunit.phar

- name: Run Tests
run: phpdbg -qrr phpunit.phar tests
- name: Checkout module
uses: actions/checkout@master
with:
submodules: true
- name: Run tests
uses: symcon/action-tests@master
21 changes: 13 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![SDK](https://img.shields.io/badge/Symcon-PHPModul-red.svg)](https://www.symcon.de/service/dokumentation/entwicklerbereich/sdk-tools/sdk-php/)
[![Version 2.2](https://img.shields.io/badge/Modul%20Version-2.2-blue.svg)]()
[![Version 5.1](https://img.shields.io/badge/Symcon%20Version-5.1%20%3E-green.svg)](https://www.symcon.de/forum/threads/30857-IP-Symcon-5-1-%28Stable%29-Changelog)
[![Version 2.21](https://img.shields.io/badge/Modul%20Version-2.21-blue.svg)]()
![Version 7.0](https://img.shields.io/badge/Symcon%20Version-7.0%20%3E-green.svg)
[![License](https://img.shields.io/badge/License-CC%20BY--NC--SA%204.0-green.svg)](https://creativecommons.org/licenses/by-nc-sa/4.0/)
[![Check Style](https://github.com/Nall-chan/VoiceRSS/workflows/Check%20Style/badge.svg)](https://github.com/Nall-chan/VoiceRSS/actions)
[![Run Tests](https://github.com/Nall-chan/VoiceRSS/workflows/Run%20Tests/badge.svg)](https://github.com/Nall-chan/VoiceRSS/actions)
Expand Down Expand Up @@ -103,19 +103,24 @@ Oder false im Fehlerfall.

**Konfiguration:**

| Eigenschaft | Typ | Standardwert | Funktion |
| :---------: | :----: | :------------: | :------------------: |
| Apikey | string | | Api-Key von VoiceRSS |
| Language | string | de-de | Sprache |
| Codec | string | MP3 | Audio-Format |
| Sample | string | 8khz_8bit_mono | Samplerate |
| Eigenschaft | Typ | Standardwert | Funktion |
| :---------: | :----: | :------------: | :-------------------------: |
| Apikey | string | | Api-Key von VoiceRSS |
| Language | string | de-de | Sprache |
| Speed | int | 0 | Geschwindigkeit -10 bis +10 |
| Voice | string | | Stimme |
| Codec | string | MP3 | Audio-Format |
| Sample | string | 8khz_8bit_mono | Samplerate |

Erlaubte Parameter siehe:
[VoiceRSS API](http://www.voicerss.org/api/documentation.aspx)


**Changelog:**

Version 2.21:
- Version für IPS 7.0.

Version 2.2:
- Sprechgeschwindigkeit und Stimme in der Konfiguration ergänzt.
- Alle ---Ex Funktionen erwarten jetzt Speed und Voice als Parameter.
Expand Down
50 changes: 26 additions & 24 deletions TTSVoiceRSS/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@
* @copyright 2019 Michael Tröger
* @license https://creativecommons.org/licenses/by-nc-sa/4.0/ CC BY-NC-SA 4.0
*
* @version 2.2
* @version 2.21
*/

/**
* TTSVoiceRSS ist die Klasse für das IPS-Modul 'TTS VoiceRSS'.
* Erweitert IPSModule.
*/
class TTSVoiceRSS extends IPSModule
class TTSVoiceRSS extends IPSModuleStrict
{
/**
* Interne Funktion des SDK.
*/
public function Create()
public function Create(): void
{
//Never delete this line!
parent::Create();
Expand All @@ -41,7 +41,7 @@ public function Create()
/**
* Interne Funktion des SDK.
*/
public function ApplyChanges()
public function ApplyChanges(): void
{
//Never delete this line!
parent::ApplyChanges();
Expand All @@ -63,7 +63,7 @@ public function ApplyChanges()
*
* @return bool True bei Erfolg, sonst false.
*/
public function GenerateFile(string $Text, string $Filename)
public function GenerateFile(string $Text, string $Filename): bool
{
$Format = $this->ReadPropertyString('Sample');
$Codec = $this->ReadPropertyString('Codec');
Expand All @@ -85,12 +85,12 @@ public function GenerateFile(string $Text, string $Filename)
*
* @return bool True bei Erfolg, sonst false.
*/
public function GenerateFileEx(string $Text, string $Filename, string $Format, string $Codec, string $Language, int $Speed, string $Voice)
public function GenerateFileEx(string $Text, string $Filename, string $Format, string $Codec, string $Language, int $Speed, string $Voice): bool
{
if ((strpos($Filename, '.' . strtolower($Codec))) === false) {
$Filename .= '.' . strtolower($Codec);
}
return $this->LoadTTSFile($Text, $Filename, $Format, $Codec, $Language, $Speed, $Voice, false);
return $this->LoadTTSFile($Text, $Filename, $Format, $Codec, $Language, $Speed, $Voice);
}

/**
Expand All @@ -101,7 +101,7 @@ public function GenerateFileEx(string $Text, string $Filename, string $Format, s
*
* @return string|bool Die Rohdaten der Sprachdatei. False im Fehlerfall.
*/
public function GetDataContent(string $Text)
public function GetDataContent(string $Text): false|string
{
$Format = $this->ReadPropertyString('Sample');
$Codec = $this->ReadPropertyString('Codec');
Expand All @@ -122,9 +122,13 @@ public function GetDataContent(string $Text)
*
* @return string|bool Die Rohdaten der Sprachdatei. False im Fehlerfall.
*/
public function GetDataContentEx(string $Text, string $Format, string $Codec, string $Language, int $Speed, string $Voice)
public function GetDataContentEx(string $Text, string $Format, string $Codec, string $Language, int $Speed, string $Voice): false|string
{
return $this->LoadTTSFile($Text, '', $Format, $Codec, $Language, $Speed, $Voice, true);
$Result = '';
if ($this->LoadTTSFile($Text, '', $Format, $Codec, $Language, $Speed, $Voice, $Result)) {
return $Result;
}
return false;
}

/**
Expand All @@ -136,7 +140,7 @@ public function GetDataContentEx(string $Text, string $Format, string $Codec, st
*
* @return int|bool Die ID des befüllten Media-Objektes. False im Fehlerfall.
*/
public function GenerateMediaObject(string $Text, int $MediaID)
public function GenerateMediaObject(string $Text, int $MediaID): false|int
{
$Format = $this->ReadPropertyString('Sample');
$Codec = $this->ReadPropertyString('Codec');
Expand All @@ -157,12 +161,12 @@ public function GenerateMediaObject(string $Text, int $MediaID)
*
* @return int|bool Die ID des befüllten Media-Objektes. False im Fehlerfall.
*/
public function GenerateMediaObjectEx(string $Text, int $MediaID, string $Format, string $Codec, string $Language, int $Speed, string $Voice)
public function GenerateMediaObjectEx(string $Text, int $MediaID, string $Format, string $Codec, string $Language, int $Speed, string $Voice): false|int
{
if ($MediaID == 0) {
$MediaID = @IPS_GetObjectIDByIdent('Voice', $this->InstanceID);
$MediaID = $this->FindIDForIdent('Voice');
}
if ($MediaID > 0) {
if ($MediaID) {
if (IPS_MediaExists($MediaID) === false) {
trigger_error('MediaObject not exists.', E_USER_NOTICE);
return false;
Expand All @@ -172,14 +176,11 @@ public function GenerateMediaObjectEx(string $Text, int $MediaID, string $Format
return false;
}
}

$raw = $this->LoadTTSFile($Text, '', $Format, $Codec, $Language, $Speed, $Voice, true);

if ($raw === false) {
$Result = '';
if (!$this->LoadTTSFile($Text, '', $Format, $Codec, $Language, $Speed, $Voice, $Result)) {
return false;
}

if ($MediaID === false) {
if (!$MediaID) {
$MediaID = IPS_CreateMedia(2);
IPS_SetMediaCached($MediaID, true);
IPS_SetName($MediaID, 'Voice');
Expand All @@ -190,7 +191,7 @@ public function GenerateMediaObjectEx(string $Text, int $MediaID, string $Format
$Filename = 'media' . DIRECTORY_SEPARATOR . $MediaID . '.' . strtolower($Codec);

IPS_SetMediaFile($MediaID, $Filename, false);
IPS_SetMediaContent($MediaID, base64_encode($raw));
IPS_SetMediaContent($MediaID, base64_encode($Result));
IPS_SetInfo($MediaID, $Text);
return $MediaID;
}
Expand All @@ -211,7 +212,7 @@ public function GenerateMediaObjectEx(string $Text, int $MediaID, string $Format
*
* @return string|bool Die Rohdaten der Sprachdatei wenn $raw = true sonst True/False im Erfolg oder Fehlerfall.
*/
private function LoadTTSFile(string $Text, string $Filename, string $Format, string $Codec, string $Language, int $Speed, string $Voice, bool $raw)
private function LoadTTSFile(string $Text, string $Filename, string $Format, string $Codec, string $Language, int $Speed, string $Voice, ?string &$raw = null): bool
{
if (trim($this->ReadPropertyString('Apikey')) == '') {
$this->SetStatus(104);
Expand Down Expand Up @@ -277,8 +278,9 @@ private function LoadTTSFile(string $Text, string $Filename, string $Format, str
return false;
}

if ($raw) {
return $result;
if ($raw !== null) {
$raw = $result;
return true;
}

try {
Expand Down
8 changes: 4 additions & 4 deletions library.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"author": "Michael Tröger",
"name": "TTS VoiceRSS Library",
"url": "https://github.com/Nall-chan/VoiceRSS",
"version": "2.2",
"build": 122,
"date": 1685102222,
"version": "2.21",
"build": 123,
"date": 1685108294,
"compatibility": {
"version": "5.1"
"version": "7.0"
}
}

0 comments on commit 7126ccb

Please sign in to comment.