From 34bc6862dbe79a0365cde0e77c9100f2ec7cd610 Mon Sep 17 00:00:00 2001 From: mikejgray Date: Sat, 6 Jan 2024 02:26:53 +0000 Subject: [PATCH 1/7] Increment Version to 0.0.2a11 --- ovos_tts_plugin_server/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ovos_tts_plugin_server/version.py b/ovos_tts_plugin_server/version.py index 3551222..67decf7 100644 --- a/ovos_tts_plugin_server/version.py +++ b/ovos_tts_plugin_server/version.py @@ -3,5 +3,5 @@ VERSION_MAJOR = 0 VERSION_MINOR = 0 VERSION_BUILD = 2 -VERSION_ALPHA = 10 +VERSION_ALPHA = 11 # END_VERSION_BLOCK From 6615adeff00d0715b413198ebb675033d5930e0a Mon Sep 17 00:00:00 2001 From: mikejgray Date: Sat, 6 Jan 2024 02:27:15 +0000 Subject: [PATCH 2/7] Update Changelog --- CHANGELOG.md | 72 ---------------------------------------------------- 1 file changed, 72 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f4e819..3b42514 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,77 +1,5 @@ # Changelog -## [0.0.2a10](https://github.com/OpenVoiceOS/ovos-tts-server-plugin/tree/0.0.2a10) (2024-01-02) - -[Full Changelog](https://github.com/OpenVoiceOS/ovos-tts-server-plugin/compare/0.0.2a9...0.0.2a10) - -**Closed issues:** - -- Test commonly used official plugins [\#13](https://github.com/OpenVoiceOS/ovos-tts-server-plugin/issues/13) - -**Merged pull requests:** - -- feat: testing and cleanup [\#14](https://github.com/OpenVoiceOS/ovos-tts-server-plugin/pull/14) ([mikejgray](https://github.com/mikejgray)) - -## [0.0.2a9](https://github.com/OpenVoiceOS/ovos-tts-server-plugin/tree/0.0.2a9) (2023-12-31) - -[Full Changelog](https://github.com/OpenVoiceOS/ovos-tts-server-plugin/compare/0.0.2a8...0.0.2a9) - -**Implemented enhancements:** - -- feat: configurable tls [\#12](https://github.com/OpenVoiceOS/ovos-tts-server-plugin/pull/12) ([mikejgray](https://github.com/mikejgray)) - -**Closed issues:** - -- Make TLS verification configurable [\#11](https://github.com/OpenVoiceOS/ovos-tts-server-plugin/issues/11) - -## [0.0.2a8](https://github.com/OpenVoiceOS/ovos-tts-server-plugin/tree/0.0.2a8) (2023-12-31) - -[Full Changelog](https://github.com/OpenVoiceOS/ovos-tts-server-plugin/compare/0.0.2a7...0.0.2a8) - -**Implemented enhancements:** - -- all servers are now on v2 [\#10](https://github.com/OpenVoiceOS/ovos-tts-server-plugin/pull/10) ([JarbasAl](https://github.com/JarbasAl)) - -## [0.0.2a7](https://github.com/OpenVoiceOS/ovos-tts-server-plugin/tree/0.0.2a7) (2023-12-31) - -[Full Changelog](https://github.com/OpenVoiceOS/ovos-tts-server-plugin/compare/0.0.2a6...0.0.2a7) - -**Implemented enhancements:** - -- endpoint\_v2 [\#8](https://github.com/OpenVoiceOS/ovos-tts-server-plugin/pull/8) ([JarbasAl](https://github.com/JarbasAl)) - -## [0.0.2a6](https://github.com/OpenVoiceOS/ovos-tts-server-plugin/tree/0.0.2a6) (2023-07-02) - -[Full Changelog](https://github.com/OpenVoiceOS/ovos-tts-server-plugin/compare/0.0.2a5...0.0.2a6) - -**Merged pull requests:** - -- removed default host of 0.0.0.0 [\#6](https://github.com/OpenVoiceOS/ovos-tts-server-plugin/pull/6) ([builderjer](https://github.com/builderjer)) - -## [0.0.2a5](https://github.com/OpenVoiceOS/ovos-tts-server-plugin/tree/0.0.2a5) (2023-07-02) - -[Full Changelog](https://github.com/OpenVoiceOS/ovos-tts-server-plugin/compare/0.0.2a4...0.0.2a5) - -**Implemented enhancements:** - -- Update TTS URLs [\#5](https://github.com/OpenVoiceOS/ovos-tts-server-plugin/pull/5) ([NeonDaniel](https://github.com/NeonDaniel)) - -## [0.0.2a4](https://github.com/OpenVoiceOS/ovos-tts-server-plugin/tree/0.0.2a4) (2023-06-26) - -[Full Changelog](https://github.com/OpenVoiceOS/ovos-tts-server-plugin/compare/0.0.2a3...0.0.2a4) - -**Fixed bugs:** - -- fix/sending\_invalid\_voice [\#3](https://github.com/OpenVoiceOS/ovos-tts-server-plugin/pull/3) ([JarbasAl](https://github.com/JarbasAl)) - -## [0.0.2a3](https://github.com/OpenVoiceOS/ovos-tts-server-plugin/tree/0.0.2a3) (2023-06-22) - -[Full Changelog](https://github.com/OpenVoiceOS/ovos-tts-server-plugin/compare/dba462d7a983e682dda23bec344001f4a0c4a612...0.0.2a3) - -**Merged pull requests:** - -- Add GitHub automation workflows [\#2](https://github.com/OpenVoiceOS/ovos-tts-server-plugin/pull/2) ([NeonDaniel](https://github.com/NeonDaniel)) - \* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)* From 17ac0e8b97057c32006c1d50487cf12d6412fc22 Mon Sep 17 00:00:00 2001 From: Mike Gray Date: Fri, 5 Jan 2024 20:36:56 -0600 Subject: [PATCH 3/7] feat: configurable tts timeout --- ovos_tts_plugin_server/__init__.py | 9 +++++- readme.md | 8 +++++- tests/e2e.py | 8 ++---- tests/main_test.py | 46 ++++++++++++------------------ 4 files changed, 36 insertions(+), 35 deletions(-) diff --git a/ovos_tts_plugin_server/__init__.py b/ovos_tts_plugin_server/__init__.py index 504d617..10f56b5 100755 --- a/ovos_tts_plugin_server/__init__.py +++ b/ovos_tts_plugin_server/__init__.py @@ -41,6 +41,11 @@ def verify_ssl(self) -> bool: """Whether or not to verify SSL certificates when connecting to the server. Defaults to True.""" return self.config.get("verify_ssl", True) + @property + def tts_timeout(self) -> int: + """Timeout for the TTS server. Defaults to 30 seconds.""" + return self.config.get("tts_timeout", 30) + def get_tts( self, sentence, @@ -81,7 +86,9 @@ def _fetch_audio_data(self, params: dict, sentence: str, servers: list) -> bytes params["utterance"] = sentence else: url = f"{url}/synthesize/{sentence}" - r: requests.Response = requests.get(url=url, params=params, verify=self.verify_ssl, timeout=30) + r: requests.Response = requests.get( + url=url, params=params, verify=self.verify_ssl, timeout=self.tts_timeout + ) if r.ok: return r.content self.log.error(f"Failed to get audio, response from {url}: {r.text}") diff --git a/readme.md b/readme.md index 9a4c291..e7e24bf 100644 --- a/readme.md +++ b/readme.md @@ -16,10 +16,16 @@ pip install ovos-tts-plugin-server "ovos-tts-plugin-server": {"host": "https://0.0.0.0:9666"}, "host": "https://tts.smartgic.io/piper", "v2": true, - "verify_ssl": true + "verify_ssl": true, + "tts_timeout": 30, } ``` +- host: the url of the tts server. `/synthesize` will be appended to it in the code +- v2: use the v2 api, if available +- verify_ssl: verify the ssl certificate of the server. If you use a self-signed certificate, you can set this to false, [but it is not recommended](#security-warning) +- tts_timeout: timeout for the request to the server. Defaults to 30 seconds. + ### As of ovos-tts-server 0.0.3a10 If using a TTS plugin with v2, you can use the `/v2` config option diff --git a/tests/e2e.py b/tests/e2e.py index 59f53a9..f26a300 100644 --- a/tests/e2e.py +++ b/tests/e2e.py @@ -8,9 +8,7 @@ from ovos_tts_plugin_server import OVOSServerTTS -def requests_retry_session( - retries=3, backoff_factor=0.3, status_forcelist=(500, 502, 503, 504) -): +def requests_retry_session(retries=3, backoff_factor=0.3, status_forcelist=(500, 502, 503, 504)): session = requests.Session() retry = Retry( total=retries, @@ -26,9 +24,7 @@ def requests_retry_session( def test_tts_plugin_e2e(): - tts_instance = OVOSServerTTS( - config={"host": "http://localhost:9666"} - ) + tts_instance = OVOSServerTTS(config={"host": "http://localhost:9666"}) tts_instance.get_tts(sentence="Hello%20world", wav_file="test.wav") assert os.path.exists(path="test.wav") assert os.path.getsize(filename="test.wav") > 0 diff --git a/tests/main_test.py b/tests/main_test.py index 8994e01..de6b7ed 100644 --- a/tests/main_test.py +++ b/tests/main_test.py @@ -41,9 +41,17 @@ def test_host_property(tts_instance, tts_instance_factory): assert custom_tts_instance.host == custom_host -@pytest.mark.parametrize( - "host,expected", [(None, True), ("https://customhost.com", False)] -) +def test_tts_timeout_property(tts_instance): + # Default behavior - No timeout set + assert tts_instance.tts_timeout == 30 + + # Custom timeout set + custom_timeout = 10 + tts_instance.config["tts_timeout"] = custom_timeout + assert tts_instance.tts_timeout == custom_timeout + + +@pytest.mark.parametrize("host,expected", [(None, True), ("https://customhost.com", False)]) def test_v2_property(tts_instance, host, expected): tts_instance.config["host"] = host assert tts_instance.v2 is expected @@ -62,9 +70,7 @@ def test_verify_ssl_property(tts_instance): assert tts_instance.verify_ssl is True -@patch( - "ovos_tts_plugin_server.OVOSServerTTS._fetch_audio_data", return_value=b"audio data" -) +@patch("ovos_tts_plugin_server.OVOSServerTTS._fetch_audio_data", return_value=b"audio data") @patch("ovos_tts_plugin_server.OVOSServerTTS._write_audio_file") def test_get_tts(mock_write_audio, mock_fetch_audio, tts_instance): sentence = "test sentence" @@ -151,14 +157,10 @@ def test_validator(tts_instance): assert tts_instance.validator.get_tts_class() == OVOSServerTTS -@patch( - "ovos_tts_plugin_server.OVOSServerTTS._fetch_audio_data", return_value=b"audio data" -) +@patch("ovos_tts_plugin_server.OVOSServerTTS._fetch_audio_data", return_value=b"audio data") @patch("ovos_tts_plugin_server.OVOSServerTTS._write_audio_file") def test_get_tts_param_change(_, fetch_audio_data, tts_instance): - tts_instance.get_tts( - sentence="test", wav_file="test.wav", lang="en-us", voice="default" - ) + tts_instance.get_tts(sentence="test", wav_file="test.wav", lang="en-us", voice="default") fetch_audio_data.assert_called_with({"lang": "en-us"}, "test", PUBLIC_TTS_SERVERS) fetch_audio_data.reset_mock() @@ -166,25 +168,17 @@ def test_get_tts_param_change(_, fetch_audio_data, tts_instance): fetch_audio_data.assert_called_with({"lang": "en-us"}, "test", PUBLIC_TTS_SERVERS) fetch_audio_data.reset_mock() - tts_instance.get_tts( - sentence="test", wav_file="test.wav", lang="en-us", voice="apope-low" - ) - fetch_audio_data.assert_called_with( - {"lang": "en-us", "voice": "apope-low"}, "test", PUBLIC_TTS_SERVERS - ) + tts_instance.get_tts(sentence="test", wav_file="test.wav", lang="en-us", voice="apope-low") + fetch_audio_data.assert_called_with({"lang": "en-us", "voice": "apope-low"}, "test", PUBLIC_TTS_SERVERS) -@patch( - "ovos_tts_plugin_server.OVOSServerTTS._fetch_audio_data", return_value=b"audio data" -) +@patch("ovos_tts_plugin_server.OVOSServerTTS._fetch_audio_data", return_value=b"audio data") @patch("ovos_tts_plugin_server.OVOSServerTTS._write_audio_file") def test_get_tts_server_lists(_, fetch_audio_data, tts_instance_factory): # Default behavior - No host set tts_instance = tts_instance_factory(config={}) tts_instance.get_tts("test", "test.wav") - fetch_audio_data.assert_called_with( - {"lang": "en-us"}, "test", tts_instance.public_servers - ) + fetch_audio_data.assert_called_with({"lang": "en-us"}, "test", tts_instance.public_servers) fetch_audio_data.reset_mock() # Custom host set custom_host = "https://customhost.com" @@ -207,9 +201,7 @@ def test_v2_property_passing(_, mock_requests, tts_instance_factory): assert tts_instance.v2 is True # Custom host set - tts_instance = tts_instance_factory( - config={"v2": False, "host": "https://customhost.com"} - ) + tts_instance = tts_instance_factory(config={"v2": False, "host": "https://customhost.com"}) assert tts_instance.v2 is False tts_instance.get_tts("test", "test.wav") mock_requests.assert_called_with( From 94559bc91d66fd88befe859e744ed85fad8edbaa Mon Sep 17 00:00:00 2001 From: Mike Gray Date: Fri, 5 Jan 2024 20:41:36 -0600 Subject: [PATCH 4/7] Revert "Update Changelog" This reverts commit 6615adeff00d0715b413198ebb675033d5930e0a. --- CHANGELOG.md | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b42514..5f4e819 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,77 @@ # Changelog +## [0.0.2a10](https://github.com/OpenVoiceOS/ovos-tts-server-plugin/tree/0.0.2a10) (2024-01-02) + +[Full Changelog](https://github.com/OpenVoiceOS/ovos-tts-server-plugin/compare/0.0.2a9...0.0.2a10) + +**Closed issues:** + +- Test commonly used official plugins [\#13](https://github.com/OpenVoiceOS/ovos-tts-server-plugin/issues/13) + +**Merged pull requests:** + +- feat: testing and cleanup [\#14](https://github.com/OpenVoiceOS/ovos-tts-server-plugin/pull/14) ([mikejgray](https://github.com/mikejgray)) + +## [0.0.2a9](https://github.com/OpenVoiceOS/ovos-tts-server-plugin/tree/0.0.2a9) (2023-12-31) + +[Full Changelog](https://github.com/OpenVoiceOS/ovos-tts-server-plugin/compare/0.0.2a8...0.0.2a9) + +**Implemented enhancements:** + +- feat: configurable tls [\#12](https://github.com/OpenVoiceOS/ovos-tts-server-plugin/pull/12) ([mikejgray](https://github.com/mikejgray)) + +**Closed issues:** + +- Make TLS verification configurable [\#11](https://github.com/OpenVoiceOS/ovos-tts-server-plugin/issues/11) + +## [0.0.2a8](https://github.com/OpenVoiceOS/ovos-tts-server-plugin/tree/0.0.2a8) (2023-12-31) + +[Full Changelog](https://github.com/OpenVoiceOS/ovos-tts-server-plugin/compare/0.0.2a7...0.0.2a8) + +**Implemented enhancements:** + +- all servers are now on v2 [\#10](https://github.com/OpenVoiceOS/ovos-tts-server-plugin/pull/10) ([JarbasAl](https://github.com/JarbasAl)) + +## [0.0.2a7](https://github.com/OpenVoiceOS/ovos-tts-server-plugin/tree/0.0.2a7) (2023-12-31) + +[Full Changelog](https://github.com/OpenVoiceOS/ovos-tts-server-plugin/compare/0.0.2a6...0.0.2a7) + +**Implemented enhancements:** + +- endpoint\_v2 [\#8](https://github.com/OpenVoiceOS/ovos-tts-server-plugin/pull/8) ([JarbasAl](https://github.com/JarbasAl)) + +## [0.0.2a6](https://github.com/OpenVoiceOS/ovos-tts-server-plugin/tree/0.0.2a6) (2023-07-02) + +[Full Changelog](https://github.com/OpenVoiceOS/ovos-tts-server-plugin/compare/0.0.2a5...0.0.2a6) + +**Merged pull requests:** + +- removed default host of 0.0.0.0 [\#6](https://github.com/OpenVoiceOS/ovos-tts-server-plugin/pull/6) ([builderjer](https://github.com/builderjer)) + +## [0.0.2a5](https://github.com/OpenVoiceOS/ovos-tts-server-plugin/tree/0.0.2a5) (2023-07-02) + +[Full Changelog](https://github.com/OpenVoiceOS/ovos-tts-server-plugin/compare/0.0.2a4...0.0.2a5) + +**Implemented enhancements:** + +- Update TTS URLs [\#5](https://github.com/OpenVoiceOS/ovos-tts-server-plugin/pull/5) ([NeonDaniel](https://github.com/NeonDaniel)) + +## [0.0.2a4](https://github.com/OpenVoiceOS/ovos-tts-server-plugin/tree/0.0.2a4) (2023-06-26) + +[Full Changelog](https://github.com/OpenVoiceOS/ovos-tts-server-plugin/compare/0.0.2a3...0.0.2a4) + +**Fixed bugs:** + +- fix/sending\_invalid\_voice [\#3](https://github.com/OpenVoiceOS/ovos-tts-server-plugin/pull/3) ([JarbasAl](https://github.com/JarbasAl)) + +## [0.0.2a3](https://github.com/OpenVoiceOS/ovos-tts-server-plugin/tree/0.0.2a3) (2023-06-22) + +[Full Changelog](https://github.com/OpenVoiceOS/ovos-tts-server-plugin/compare/dba462d7a983e682dda23bec344001f4a0c4a612...0.0.2a3) + +**Merged pull requests:** + +- Add GitHub automation workflows [\#2](https://github.com/OpenVoiceOS/ovos-tts-server-plugin/pull/2) ([NeonDaniel](https://github.com/NeonDaniel)) + \* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)* From 97fe2c8c784fc36f990a2bf46ca7d891eb00bd8b Mon Sep 17 00:00:00 2001 From: Mike Gray Date: Fri, 5 Jan 2024 20:41:47 -0600 Subject: [PATCH 5/7] Revert "Increment Version to 0.0.2a11" This reverts commit 34bc6862dbe79a0365cde0e77c9100f2ec7cd610. --- ovos_tts_plugin_server/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ovos_tts_plugin_server/version.py b/ovos_tts_plugin_server/version.py index 67decf7..3551222 100644 --- a/ovos_tts_plugin_server/version.py +++ b/ovos_tts_plugin_server/version.py @@ -3,5 +3,5 @@ VERSION_MAJOR = 0 VERSION_MINOR = 0 VERSION_BUILD = 2 -VERSION_ALPHA = 11 +VERSION_ALPHA = 10 # END_VERSION_BLOCK From f2af26dd12a2b1bb02000e3ba1219f5f095fdbb2 Mon Sep 17 00:00:00 2001 From: Mike Gray Date: Sat, 6 Jan 2024 16:54:01 -0600 Subject: [PATCH 6/7] adjust default timeout to 5s add a test helper script --- ovos_tts_plugin_server/__init__.py | 4 ++-- tests.sh | 14 ++++++++++++++ tests/main_test.py | 4 ++-- 3 files changed, 18 insertions(+), 4 deletions(-) create mode 100755 tests.sh diff --git a/ovos_tts_plugin_server/__init__.py b/ovos_tts_plugin_server/__init__.py index 10f56b5..c215d44 100755 --- a/ovos_tts_plugin_server/__init__.py +++ b/ovos_tts_plugin_server/__init__.py @@ -43,8 +43,8 @@ def verify_ssl(self) -> bool: @property def tts_timeout(self) -> int: - """Timeout for the TTS server. Defaults to 30 seconds.""" - return self.config.get("tts_timeout", 30) + """Timeout for the TTS server. Defaults to 5 seconds.""" + return self.config.get("tts_timeout", 5) def get_tts( self, diff --git a/tests.sh b/tests.sh new file mode 100755 index 0000000..0cec4c7 --- /dev/null +++ b/tests.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +pip install -r requirements-dev.txt +pip install . + +black --line-length=119 . +bandit -ll -r ovos_tts_plugin_server +flake8 --max-line-length=119 ovos_tts_plugin_server +isort --profile black . +ruff ovos_tts_plugin_server +mypy --ignore-missing-imports --exclude tests ovos_tts_plugin_server +safety check --ignore=58755 --continue-on-error + +pytest diff --git a/tests/main_test.py b/tests/main_test.py index de6b7ed..0411277 100644 --- a/tests/main_test.py +++ b/tests/main_test.py @@ -43,7 +43,7 @@ def test_host_property(tts_instance, tts_instance_factory): def test_tts_timeout_property(tts_instance): # Default behavior - No timeout set - assert tts_instance.tts_timeout == 30 + assert tts_instance.tts_timeout == 5 # Custom timeout set custom_timeout = 10 @@ -208,5 +208,5 @@ def test_v2_property_passing(_, mock_requests, tts_instance_factory): url="https://customhost.com/synthesize/test", params={"lang": "en-us"}, verify=True, - timeout=30, + timeout=5, ) From 97ca19c4644f26a59e932beb4824a95890b17a42 Mon Sep 17 00:00:00 2001 From: Mike Gray Date: Sat, 6 Jan 2024 16:58:50 -0600 Subject: [PATCH 7/7] docs --- readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index e7e24bf..b04f8f8 100644 --- a/readme.md +++ b/readme.md @@ -17,14 +17,14 @@ pip install ovos-tts-plugin-server "host": "https://tts.smartgic.io/piper", "v2": true, "verify_ssl": true, - "tts_timeout": 30, + "tts_timeout": 5, } ``` - host: the url of the tts server. `/synthesize` will be appended to it in the code - v2: use the v2 api, if available - verify_ssl: verify the ssl certificate of the server. If you use a self-signed certificate, you can set this to false, [but it is not recommended](#security-warning) -- tts_timeout: timeout for the request to the server. Defaults to 30 seconds. +- tts_timeout: timeout for the request to the server. Defaults to 5 seconds. ### As of ovos-tts-server 0.0.3a10