Skip to content

Commit

Permalink
change alexa_voice_service to avs
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongyihui committed Jul 4, 2017
1 parent 73cbbea commit 37fb0c3
Show file tree
Hide file tree
Showing 20 changed files with 214 additions and 63 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
deploy:
true:
python: 2.7
repo: respeaker/alexa_voice_service
repo: respeaker/avs
tags: true
distributions: sdist bdist_wheel
password:
secure: QMQoAOYniJ067+2X71ZHqff2f6U4F3Q0WKNwSzovGoMoyoYzIpxs7szyL49yYRq3Xy4WE1+6DxcDWs40YDwB7Zh/fTsKYbhejU5MMyOscK0lr84lbrvXokKpWmJGhToH7+Z6Eo/8UasnL0rseIneLp424jP5c+VSbtZ1NIPNMiTG+D2S1eut68tXZouQNJG1qSrJN2+5WU3krdhfWEjY6YrJRHR6/fpR9lFMoAjx80f1fU6opIGu2ARfOGnzbgaba83GfpLJIy1Bw1OJt3YnkFOc4ctWZ08eZ19TLMxKjWBAN5Ks9e195vlDq8Nc/48N1ZEBG+qHJovZmm4q8N62ofufMHV6N69QoM4tq16ks5uAhvrndP8LSiDziA5mCJWEh7ibYUr22i/2OdFt3Cnvlp/GjJxNiRZoFFMwFKTmvq4lYGmjsTS8X3g0abcBsrADjNhOdpo7UHWXWmrPuMd0ASx4LH94+dixn0TJdp3p7OqzkWpBXpFklwcsYM+fN68g7+FN60w0vu6fk5z+oJI3RPWOdLUPLquvON4FZZFElcIgBdlIrWp66ijkD8iM5mhQpt6WL90wPgExyjvkX4WfxGoLeqEN6Icr8NAG1so1mmUIs8Idp0B+Jj93O6rynkl1OgZXtStRCdxAld+WWUshsSA+9CvS2Pi5A5oBximYT44=
secure: F1qdw8lUDQJpXvoAH/8nP43exXx6wnUgJR0FPfmnDi30iJpyjK/sr05xKcHJ+RNHuyzs82p9c3oR+f8IT2OC2VmKb18F/9VDiGu5YHEi+mEzJoJKQmsnnaZYe0gWyi3DLuwwO3am4Pnia83UBfBStWpecWz00nCw69AMtXTljUb2xwpypCw3bYvkuKTp36umHLVsWDc8zitLgJnYWYHYralInunFZuwl+FV0nB0KBgaenHEhHd5R+pfBNDc6Qhe9JKEiPq8gunMNj3h86q1hksWN7peGNeJ6ynrFEsAZwrjeyJPzDeA/dx4DvsMbcdy6/JIj9RcoBXDsJfKb17El86JEbSGWA6LX+tZlc5Hdp0zurYs4Vb9T8uu5omp4IfHvhqNTlCMSYQRUKtriGoj/VBdB6ZG/RIoTkKAF2IOW9Ww/GDi5b507V7/ZuyVOnq9pnk4QeayPZvzCswRmsJL0BTXAJK3uN0JMNq/yhpjofWqAqZPG7FBrZJjwGgULk5oqkCgGmi2xqg2Kte5wpUgvo9tUOaC59pahyHulTwA3mgnPKld7pWJBixHyAxEvrDvLjitVNpuEXYfFq7sINqKMJURnW+C1Eb8Fs893aOak6DxRpB77Ox79/wA7/9ESZ5V3n/LMVNwEa8WAY0c7qDyh7rknXxj7VxN+7I7C3D2qsE0=
provider: pypi
user: xiongyihui
user: yihui
install: pip install -U tox-travis
language: python
python:
Expand Down
114 changes: 114 additions & 0 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
.. highlight:: shell

============
Contributing
============

Contributions are welcome, and they are greatly appreciated! Every
little bit helps, and credit will always be given.

You can contribute in many ways:

Types of Contributions
----------------------

Report Bugs
~~~~~~~~~~~

Report bugs at https://github.com/respeaker/avs/issues.

If you are reporting a bug, please include:

* Your operating system name and version.
* Any details about your local setup that might be helpful in troubleshooting.
* Detailed steps to reproduce the bug.

Fix Bugs
~~~~~~~~

Look through the GitHub issues for bugs. Anything tagged with "bug"
and "help wanted" is open to whoever wants to implement it.

Implement Features
~~~~~~~~~~~~~~~~~~

Look through the GitHub issues for features. Anything tagged with "enhancement"
and "help wanted" is open to whoever wants to implement it.

Write Documentation
~~~~~~~~~~~~~~~~~~~

Python Alexa Voice Service could always use more documentation, whether as part of the
official Python Alexa Voice Service docs, in docstrings, or even on the web in blog posts,
articles, and such.

Submit Feedback
~~~~~~~~~~~~~~~

The best way to send feedback is to file an issue at https://github.com/respeaker/avs/issues.

If you are proposing a feature:

* Explain in detail how it would work.
* Keep the scope as narrow as possible, to make it easier to implement.
* Remember that this is a volunteer-driven project, and that contributions
are welcome :)

Get Started!
------------

Ready to contribute? Here's how to set up `avs` for local development.

1. Fork the `avs` repo on GitHub.
2. Clone your fork locally::

$ git clone [email protected]:your_name_here/avs.git

3. Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development::

$ mkvirtualenv avs
$ cd avs/
$ python setup.py develop

4. Create a branch for local development::

$ git checkout -b name-of-your-bugfix-or-feature

Now you can make your changes locally.

5. When you're done making changes, check that your changes pass flake8 and the tests, including testing other Python versions with tox::

$ flake8 avs tests
$ python setup.py test or py.test
$ tox

To get flake8 and tox, just pip install them into your virtualenv.

6. Commit your changes and push your branch to GitHub::

$ git add .
$ git commit -m "Your detailed description of your changes."
$ git push origin name-of-your-bugfix-or-feature

7. Submit a pull request through the GitHub website.

Pull Request Guidelines
-----------------------

Before you submit a pull request, check that it meets these guidelines:

1. The pull request should include tests.
2. If the pull request adds functionality, the docs should be updated. Put
your new functionality into a function with a docstring, and add the
feature to the list in README.rst.
3. The pull request should work for Python 2.6, 2.7, 3.3, 3.4 and 3.5, and for PyPy. Check
https://travis-ci.org/respeaker/avs/pull_requests
and make sure that the tests pass for all supported Python versions.

Tips
----

To run a subset of tests::


$ python -m unittest tests.test_avs
26 changes: 13 additions & 13 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
==========================
Python Alexa Voice Service
==========================
==============================
Python Alexa Voice Service App
==============================


.. image:: https://img.shields.io/pypi/v/alexa_voice_service.svg
:target: https://pypi.python.org/pypi/alexa_voice_service
.. image:: https://img.shields.io/pypi/v/avs.svg
:target: https://pypi.python.org/pypi/avs

.. image:: https://img.shields.io/travis/respeaker/alexa_voice_service.svg
:target: https://travis-ci.org/respeaker/alexa_voice_service
.. image:: https://img.shields.io/travis/respeaker/avs.svg
:target: https://travis-ci.org/respeaker/avs

.. image:: https://readthedocs.org/projects/alexa-voice-service/badge/?version=latest
:target: https://alexa-voice-service.readthedocs.io/en/latest/?badge=latest
.. image:: https://readthedocs.org/projects/avs/badge/?version=latest
:target: https://avs.readthedocs.io/en/latest/?badge=latest
:alt: Documentation Status

.. image:: https://pyup.io/repos/github/respeaker/alexa_voice_service/shield.svg
:target: https://pyup.io/repos/github/respeaker/alexa_voice_service/
.. image:: https://pyup.io/repos/github/respeaker/avs/shield.svg
:target: https://pyup.io/repos/github/respeaker/avs
:alt: Updates


Python implementation of Alexa Voice Service
Python implementation of Alexa Voice Service app


* Free software: GNU General Public License v3
* Documentation: https://alexa-voice-service.readthedocs.io.
* Documentation: https://avs.readthedocs.io.


Features
Expand Down
2 changes: 1 addition & 1 deletion alexa_voice_service/__init__.py → avs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

__author__ = """Yihui Xiong"""
__email__ = '[email protected]'
__version__ = '0.1.0'
__version__ = '0.0.1'
26 changes: 12 additions & 14 deletions alexa_voice_service/alexa_voice_service.py → avs/alexa.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
log = logging.getLogger(__name__)


class AlexaVoiceService(object):
class Alexa(object):
API_VERSION = 'v20160207'

def __init__(self, tokens_filename, audio):
Expand All @@ -54,7 +54,7 @@ def start(self):
t = threading.Thread(target=self.loop)
t.daemon = True
t.start()
self.ready.wait(6)
self.ready.wait()

def stop(self):
self.done.set()
Expand Down Expand Up @@ -389,29 +389,27 @@ def __exit__(self, exc_type, exc_val, exc_tb):
self.stop()


def main(tokens):
def main():
from mic import Mic
import sys

if len(sys.argv) < 2:
print('Usage: {} tokens.json'.format(sys.argv[0]))
sys.exit(1)

mic = Mic()
with AlexaVoiceService(tokens, mic) as alexa:
audio = Mic()
with Alexa(sys.argv[1], audio) as alexa:
while True:
try:
try:
input('press ENTER to talk with alexa')
except SyntaxError:
pass

mic.start()
alexa.SpeechRecognizer.Recognize(mic)
alexa.SpeechRecognizer.Recognize(audio).wait(20)
except KeyboardInterrupt:
break


if __name__ == '__main__':
import sys

if len(sys.argv) < 2:
print('Usage: {} tokens.json'.format(sys.argv[0]))
sys.exit(1)

main(sys.argv[1])
main()
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class SpeechRecognizer(object):
def __init__(self, alexa):
self.alexa = alexa
self.profile = 'NEAR_FIELD'
self.stop = Event()
self.done = Event()

def Recognize(self, audio, dialog=None, initiator=None, timeout=12000):
if dialog is None:
Expand All @@ -39,20 +39,26 @@ def Recognize(self, audio, dialog=None, initiator=None, timeout=12000):
}
}

audio.start()
self.done.clear()

def gen():
with audio as chunks:
self.stop.clear()
time_elapsed = 0
for chunk in chunks:
if self.stop.is_set() or time_elapsed >= timeout:
log.info('stop recording')
break
yield chunk
time_elapsed += 10 # 10 ms chunk
time_elapsed = 0
for chunk in audio:
if self.done.is_set() or time_elapsed >= timeout:
log.info('stop recording')
break
yield chunk
time_elapsed += 10 # 10 ms chunk

audio.stop()
self.done.set()

event['attachment'] = gen()
self.alexa.event_queue.put(event)

return self.done

# {
# "directive": {
# "header": {
Expand All @@ -66,7 +72,7 @@ def gen():
# }
# }
def StopCapture(self, directive):
self.stop.set()
self.done.set()
log.info('StopCapture')

# {
Expand Down
File renamed without changes.
File renamed without changes.
29 changes: 16 additions & 13 deletions alexa_voice_service/mic.py → avs/mic.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,21 @@ def _callback(self, in_data, frame_count, time_info, status):
return None, pyaudio.paContinue

def start(self):
self.queue.queue.clear()
self.stream.start_stream()
log.debug('start recording')
if self.stream.is_stopped():
self.queue.queue.clear()
self.stream.start_stream()
log.info('start recording')
else:
log.info('already started')

def stop(self):
if not self.stream.is_stopped():
self.quit_event.set()
self.stream.stop_stream()
self.queue.put('')
log.info('stop recording')
else:
log.info('already stopped')

def read_chunked(self):
self.quit_event.clear()
Expand All @@ -58,23 +69,15 @@ def read_chunked(self):

yield frames

def stop(self):
self.quit_event.set()
self.stream.stop_stream()
self.queue.put('')
log.debug('stop recording')

def __enter__(self):
if self.stream.is_stopped():
self.start()
self.start()
return self

def __exit__(self, exc_type, exc_val, exc_tb):
self.stop()

def __iter__(self):
if self.stream.is_stopped():
self.start()
self.start()
return self.read_chunked()


Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ tag = True
search = version='{current_version}'
replace = version='{new_version}'

[bumpversion:file:alexa_voice_service/__init__.py]
[bumpversion:file:avs/__init__.py]
search = __version__ = '{current_version}'
replace = __version__ = '{new_version}'

Expand Down
17 changes: 11 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,24 @@
]

setup(
name='alexa_voice_service',
version='0.1.0',
description="Python implementation of Alexa Voice Service",
name='avs',
version='0.0.1',
description="Python implementation of Alexa Voice Service App",
long_description=readme + '\n\n' + history,
author="Yihui Xiong",
author_email='[email protected]',
url='https://github.com/respeaker/alexa_voice_service',
packages=find_packages(include=['alexa_voice_service']),
url='https://github.com/respeaker/avs',
packages=find_packages(include=['avs']),
include_package_data=True,
install_requires=requirements,
entry_points={
'console_scripts': [
'alexa=avs.alexa:main'
],
},
license="GNU General Public License v3",
zip_safe=False,
keywords='alexa_voice_service',
keywords='alexa voice service',
classifiers=[
'Development Status :: 2 - Pre-Alpha',
'Intended Audience :: Developers',
Expand Down
3 changes: 3 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-

"""Unit test package for avs."""
Loading

0 comments on commit 37fb0c3

Please sign in to comment.