-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* InitialImplementation * Remove copy/pasted TODO from nemo plugin * Add missing setup.py Remove Docker build tests * Strip wrapping '"' and add unit test case --------- Co-authored-by: Daniel McKnight <daniel@neon.ai>
- Loading branch information
1 parent
a85147b
commit 16a21ce
Showing
18 changed files
with
390 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
name: Run License Tests | ||
on: | ||
push: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
license_tests: | ||
uses: neongeckocom/.github/.github/workflows/license_tests.yml@master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Propose Stable Release | ||
on: | ||
workflow_dispatch: | ||
inputs: | ||
release_type: | ||
type: choice | ||
description: Release Type | ||
options: | ||
- patch | ||
- minor | ||
- major | ||
jobs: | ||
update_version: | ||
uses: neongeckocom/.github/.github/workflows/propose_semver_release.yml@master | ||
with: | ||
branch: dev | ||
release_type: ${{ inputs.release_type }} | ||
update_changelog: True | ||
pull_changes: | ||
uses: neongeckocom/.github/.github/workflows/pull_master.yml@master | ||
needs: update_version | ||
with: | ||
pr_reviewer: neonreviewers | ||
pr_assignee: ${{ github.actor }} | ||
pr_draft: false | ||
pr_title: ${{ needs.update_version.outputs.version }} | ||
pr_body: ${{ needs.update_version.outputs.changelog }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# This workflow will generate a release distribution and upload it to PyPI | ||
|
||
name: Publish Build and GitHub Release | ||
on: | ||
push: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
build_and_publish_pypi_and_release: | ||
uses: neongeckocom/.github/.github/workflows/publish_stable_release.yml@master | ||
secrets: inherit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# This workflow will generate a distribution and upload it to PyPI | ||
|
||
name: Publish Alpha Build | ||
on: | ||
push: | ||
branches: | ||
- dev | ||
paths-ignore: | ||
- 'version.py' | ||
|
||
jobs: | ||
publish_alpha_release: | ||
uses: neongeckocom/.github/.github/workflows/publish_alpha_release.yml@master | ||
secrets: inherit | ||
with: | ||
version_file: "version.py" | ||
setup_py: "setup.py" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# This workflow will run unit tests | ||
|
||
name: Run Unit Tests | ||
on: | ||
pull_request: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
py_build_tests: | ||
uses: neongeckocom/.github/.github/workflows/python_build_tests.yml@master | ||
unit_tests: | ||
strategy: | ||
matrix: | ||
python-version: [ 3.7, 3.8, 3.9 ] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install dependencies | ||
run: | | ||
sudo apt update | ||
sudo apt install gcc ffmpeg portaudio19-dev python3-pyaudio libpulse-dev | ||
pip install wheel | ||
pip install Cython | ||
python -m pip install --upgrade pip | ||
pip install -r requirements/requirements.txt | ||
pip install -r requirements/test_requirements.txt | ||
- name: Test Nemo Remote STT | ||
run: | | ||
pytest tests/test_stt.py --junitxml=tests/stt-test-results.xml | ||
- name: Upload STT test results | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: pytest-results-3.7 | ||
path: tests/stt-test-results.xml | ||
if: ${{ always() }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# NEON AI (TM) SOFTWARE, Software Development Kit & Application Development System | ||
# All trademark and other rights reserved by their respective owners | ||
# Copyright 2008-2021 Neongecko.com Inc. | ||
# BSD-3 License | ||
|
||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the | ||
following conditions are met: | ||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following | ||
disclaimer. | ||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following | ||
disclaimer in the documentation and/or other materials provided with the distribution. | ||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products | ||
derived from this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# NeonAI Nemo Remote STT Plugin | ||
[Mycroft](https://mycroft-ai.gitbook.io/docs/mycroft-technologies/mycroft-core/plugins) compatible | ||
Neon Nemo Remote Speech-to-Text Plugin. | ||
|
||
## Configuration: | ||
```yaml | ||
stt: | ||
module: neon-stt-plugin-nemo-remote | ||
neon-stt-plugin-nemo: | ||
url: "https://nemo.neonaialpha.com" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# NEON AI (TM) SOFTWARE, Software Development Kit & Application Framework | ||
# All trademark and other rights reserved by their respective owners | ||
# Copyright 2008-2022 Neongecko.com Inc. | ||
# Contributors: Daniel McKnight, Guy Daniels, Elon Gasper, Richard Leeds, | ||
# Regina Bloomstine, Casimiro Ferreira, Andrii Pernatii, Kirill Hrymailo | ||
# BSD-3 License | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions are met: | ||
# 1. Redistributions of source code must retain the above copyright notice, | ||
# this list of conditions and the following disclaimer. | ||
# 2. Redistributions in binary form must reproduce the above copyright notice, | ||
# this list of conditions and the following disclaimer in the documentation | ||
# and/or other materials provided with the distribution. | ||
# 3. Neither the name of the copyright holder nor the names of its | ||
# contributors may be used to endorse or promote products derived from this | ||
# software without specific prior written permission. | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | ||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, | ||
# OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
import requests | ||
|
||
from ovos_plugin_manager.templates.stt import STT | ||
from ovos_utils.log import LOG | ||
from speech_recognition import AudioData | ||
|
||
|
||
class NemoRemoteSTT(STT): | ||
default_lang = "en" | ||
public_servers = ["https://nemo.neonaialpha.com"] | ||
|
||
def __init__(self, config: dict = None): | ||
super().__init__(config) | ||
self.lang = self.config.get('lang') or self.default_lang | ||
self.url = self.config.get('url') | ||
self.api_path = "/stt" | ||
self.transcriptions = [] | ||
|
||
@staticmethod | ||
def _get_response(audio: AudioData, lang: str, url: str): | ||
return requests.post(url, data=audio.get_wav_data(), | ||
headers={"Content-Type": "audio/wav"}, | ||
params={"lang": lang}) | ||
|
||
def _get_from_public_servers(self, audio: AudioData, lang: str) -> str: | ||
for url in self.public_servers: | ||
try: | ||
r = self._get_response(audio, lang, f"{url}{self.api_path}") | ||
if r.ok: | ||
return r.text.strip('"') | ||
except: | ||
continue | ||
raise RuntimeError(f"All Nemo public servers are down.") | ||
|
||
def execute(self, audio: AudioData, language: str = None) -> str: | ||
""" | ||
Get STT for the given audio data in the specified language | ||
@param audio: Input audio data to process | ||
@param language: Language of input audio | ||
""" | ||
lang = language or self.lang | ||
|
||
# Check configured endpoint | ||
if self.url: | ||
if self.url.endswith(self.api_path): | ||
url = self.url | ||
else: | ||
url = f"{self.url}{self.api_path}" | ||
resp = self._get_response(audio, lang, url) | ||
if resp.ok: | ||
tx = resp.text.strip('"') | ||
LOG.info(f"Transcribed: {tx}") | ||
return tx | ||
|
||
try: | ||
LOG.debug("Get STT from public servers") | ||
tx = self._get_from_public_servers(audio, lang) | ||
LOG.info(f"Transcribed: {tx}") | ||
return tx | ||
except Exception as e: | ||
LOG.exception(e) | ||
return "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
ovos-plugin-manager~=0.0.24 | ||
ovos-utils~=0.0.30 | ||
SpeechRecognition~=3.8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pytest | ||
pytest-timeout |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# NEON AI (TM) SOFTWARE, Software Development Kit & Application Development System | ||
# | ||
# Copyright 2008-2021 Neongecko.com Inc. | All Rights Reserved | ||
# | ||
# Notice of License - Duplicating this Notice of License near the start of any file containing | ||
# a derivative of this software is a condition of license for this software. | ||
# Friendly Licensing: | ||
# No charge, open source royalty free use of the Neon AI software source and object is offered for | ||
# educational users, noncommercial enthusiasts, Public Benefit Corporations (and LLCs) and | ||
# Social Purpose Corporations (and LLCs). Developers can contact developers@neon.ai | ||
# For commercial licensing, distribution of derivative works or redistribution please contact licenses@neon.ai | ||
# Distributed on an "AS IS” basis without warranties or conditions of any kind, either express or implied. | ||
# Trademarks of Neongecko: Neon AI(TM), Neon Assist (TM), Neon Communicator(TM), Klat(TM) | ||
# Authors: Guy Daniels, Daniel McKnight, Regina Bloomstine, Elon Gasper, Richard Leeds | ||
# | ||
# Specialized conversational reconveyance options from Conversation Processing Intelligence Corp. | ||
# US Patents 2008-2021: US7424516, US20140161250, US20140177813, US8638908, US8068604, US8553852, US10530923, US10530924 | ||
# China Patent: CN102017585 - Europe Patent: EU2156652 - Patents Pending | ||
|
||
from setuptools import setup, find_packages | ||
from os import getenv, path | ||
|
||
|
||
BASE_PATH = path.abspath(path.dirname(__file__)) | ||
|
||
|
||
def get_requirements(requirements_filename: str): | ||
requirements_file = path.join(BASE_PATH, "requirements", requirements_filename) | ||
with open(requirements_file, 'r', encoding='utf-8') as r: | ||
requirements = r.readlines() | ||
requirements = [r.strip() for r in requirements if r.strip() and not r.strip().startswith("#")] | ||
|
||
for i in range(0, len(requirements)): | ||
r = requirements[i] | ||
if "@" in r: | ||
parts = [p.lower() if p.strip().startswith("git+http") else p for p in r.split('@')] | ||
r = "@".join(parts) | ||
if getenv("GITHUB_TOKEN"): | ||
if "github.com" in r: | ||
r = r.replace("github.com", f"{getenv('GITHUB_TOKEN')}@github.com") | ||
requirements[i] = r | ||
return requirements | ||
|
||
|
||
PLUGIN_ENTRY_POINT = 'neon-stt-plugin-nemo-remote = neon_stt_plugin_nemo_remote:NemoRemoteSTT' | ||
|
||
|
||
with open(path.join(BASE_PATH, "README.md"), "r") as f: | ||
long_description = f.read() | ||
|
||
|
||
with open(path.join(BASE_PATH, "version.py"), "r", encoding="utf-8") as v: | ||
for line in v.readlines(): | ||
if line.startswith("__version__"): | ||
if '"' in line: | ||
version = line.split('"')[1] | ||
else: | ||
version = line.split("'")[1] | ||
|
||
setup( | ||
name='neon-stt-plugin-nemo-remote', | ||
version=version, | ||
description='Nemo Remote STT plugin for Neon', | ||
long_description=long_description, | ||
long_description_content_type="text/markdown", | ||
url='https://github.com/NeonGeckoCom/neon-stt-plugin-nemo-remote', | ||
author='Neongecko', | ||
author_email='developers@neon.ai', | ||
license='BSD-3.0', | ||
packages=find_packages(), | ||
package_data={"neon_stt_plugin_nemo": ["*.yml"]}, | ||
install_requires=get_requirements("requirements.txt"), | ||
zip_safe=True, | ||
classifiers=[ | ||
'Intended Audience :: Developers', | ||
'Topic :: Text Processing :: Linguistic', | ||
'Programming Language :: Python :: 3.8', | ||
], | ||
keywords='mycroft plugin stt', | ||
entry_points={'mycroft.plugin.stt': PLUGIN_ENTRY_POINT} | ||
) |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# NEON AI (TM) SOFTWARE, Software Development Kit & Application Framework | ||
# All trademark and other rights reserved by their respective owners | ||
# Copyright 2008-2022 Neongecko.com Inc. | ||
# Contributors: Daniel McKnight, Guy Daniels, Elon Gasper, Richard Leeds, | ||
# Regina Bloomstine, Casimiro Ferreira, Andrii Pernatii, Kirill Hrymailo | ||
# BSD-3 License | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions are met: | ||
# 1. Redistributions of source code must retain the above copyright notice, | ||
# this list of conditions and the following disclaimer. | ||
# 2. Redistributions in binary form must reproduce the above copyright notice, | ||
# this list of conditions and the following disclaimer in the documentation | ||
# and/or other materials provided with the distribution. | ||
# 3. Neither the name of the copyright holder nor the names of its | ||
# contributors may be used to endorse or promote products derived from this | ||
# software without specific prior written permission. | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | ||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, | ||
# OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
import os | ||
import sys | ||
import unittest | ||
import speech_recognition as sr | ||
|
||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) | ||
from neon_stt_plugin_nemo_remote import NemoRemoteSTT | ||
|
||
ROOT_DIR = os.path.dirname(os.path.realpath(__file__)) | ||
TEST_PATH = os.path.join(ROOT_DIR, "test_audio") | ||
|
||
|
||
class TestGetSTT(unittest.TestCase): | ||
def setUp(self) -> None: | ||
self.stt = NemoRemoteSTT({'lang': 'en'}) | ||
|
||
def test_get_stt(self): | ||
r = sr.Recognizer() | ||
for file in os.listdir(TEST_PATH): | ||
transcription = os.path.splitext(os.path.basename(file))[0].lower() | ||
audio_path = os.path.join(TEST_PATH, file) | ||
with sr.AudioFile(audio_path) as source: | ||
audio = r.record(source) # read the entire audio file | ||
result = self.stt.execute(audio) | ||
self.assertFalse(result.startswith('"')) | ||
self.assertIn(transcription, result) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
Oops, something went wrong.