Skip to content
This repository was archived by the owner on May 6, 2022. It is now read-only.

Commit 49f15d8

Browse files
authored
Organization and Content update to the README (#29)
README content update
1 parent 867b72d commit 49f15d8

File tree

2 files changed

+148
-23
lines changed

2 files changed

+148
-23
lines changed

README.md

Lines changed: 148 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,196 @@
1-
# spokestack-python
1+
# Spokestack Python
22

3-
## Status
3+
<p align="center">
4+
<img width="100" height="100" src="images/spokestack.png">
5+
</p>
46

7+
[![GitHub license](https://img.shields.io/github/license/spokestack/spokestack-python)](https://github.com/spokestack/spokestack-python/blob/master/LICENSE.txt)
58
[![CircleCI](https://circleci.com/gh/pylon/streamp3.svg?style=shield)](https://circleci.com/gh/spokestack/spokestack-python)
69
[![PyPI version](https://badge.fury.io/py/spokestack.svg)](https://badge.fury.io/py/spokestack)
710
[![Coverage Status](https://coveralls.io/repos/github/spokestack/spokestack-python/badge.svg?branch=master)](https://coveralls.io/github/spokestack/spokestack-python?branch=master)
811
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
9-
[![Documentation Status](https://readthedocs.org/projects/spokestack/badge/?version=latest)](https://spokestack.readthedocs.io/en/latest/?badge=latest)
12+
[![GitHub stars](https://img.shields.io/github/stars/spokestack/spokestack-python?style=social)](https://github.com/spokestack/spokestack-python/stargazers)
13+
![GitHub watchers](https://img.shields.io/github/watchers/spokestack/spokestack-python?style=social)
14+
![Twitter Follow](https://img.shields.io/twitter/follow/spokestack?style=social)
15+
16+
Welcome to Spokestack Python! This library is intended for developing [voice interfaces](https://en.wikipedia.org/wiki/Voice_user_interface) in Python. This can include anything from [Raspberry Pi](https://www.raspberrypi.org/) applications like traditional smart speakers to [Django](https://www.djangoproject.com/) web applications. _Anything_ built in [Python](https://www.python.org/) can be given a voice interface.
1017

1118
## Get Started
1219

1320
### System Dependencies
1421

22+
There are some system dependencies that need to be downloaded in order to install spokestack via pip.
23+
1524
#### macOS
1625

17-
brew install lame portaudio
26+
```shell
27+
brew install lame portaudio
28+
```
1829

1930
#### Debian/Ubuntu
2031

21-
sudo apt-get install portaudio19-dev libmp3lame-dev
32+
```shell
33+
sudo apt-get install portaudio19-dev libmp3lame-dev
34+
```
35+
36+
#### Windows
37+
38+
We currently do not support Windows 10 natively, and recommend you install [Windows Subsystem for Linux (WSL)](https://docs.microsoft.com/en-us/windows/wsl/install-win10) with the Debian dependencies. However, if you would like to work on native Windows support we will glady accept pull requests.
39+
40+
Another potential avenue for using `spokestack` on Windows 10 is from [anaconda](https://www.anaconda.com/). This is without support for Text To Speech (TTS) though due to the Lame dependency. PortAudio, on the other hand, can be installed via `conda`.
2241

23-
Add voice capability to your projects with one line.
42+
```shell
43+
conda install portaudio
44+
```
2445

25-
pip install spokestack
46+
### Installation with pip
2647

27-
## Development
48+
Once system dependencies have been satisfied, you can install the library with the following.
49+
50+
```shell
51+
pip install spokestack
52+
```
2853

2954
### Setup
3055

3156
We use `pyenv` for virtual environments. Below you will find the step-by-step commands to install a virtual environment.
3257

33-
pyenv install 3.8.6
34-
pyenv virtualenv 3.8.6 spokestack
35-
pyenv local spokestack
36-
pip install -r requirements.txt
58+
```shell
59+
pyenv install 3.8.6
60+
pyenv virtualenv 3.8.6 spokestack
61+
pyenv local spokestack
62+
pip install -r requirements.txt
63+
```
64+
65+
### Install Tensorflow
66+
67+
This library requires a way to run [TFLite](https://www.tensorflow.org/lite) models. There are two ways to add this ability. The first is installing the full [Tensorflow](https://www.tensorflow.org/) library.
68+
69+
The full Tensorflow package is installed with the following:
70+
71+
```shell
72+
pip install tensorflow
73+
```
74+
75+
#### TFLite Interpreter (Embedded Devices)
76+
77+
In use cases where you require a small footprint, such as on a Raspberry Pi or similar embedded devices, you will want to install the TFLite Interpreter. You can install it for your platform by [following the instructions](https://www.tensorflow.org/lite/guide/python#install_just_the_tensorflow_lite_interpreter).
78+
79+
## Usage
80+
81+
### Speech Pipeline
82+
83+
The Speech Pipeline is the module that ties together VAD (voice activity detection), wakeword, and ASR (automated speech detection). The VAD listens to a frame of audio captured by the input device to determine if speech is present. If it is, the wakeword model processes subsequent frames of audio looking for the keyword it has been trained to recognize. If the keyword is found, the pipeline is activated and performs speech recognition, converting the subsequent audio into a transcript. The Speech Pipeline is initialized like this:
84+
85+
```python
86+
from spokestack.io.pyaudio import PyAudioInput
87+
from spokestack.pipeline import SpeechPipeline
88+
from spokestack.vad.webrtc import VoiceActivityDetector
89+
from spokestack.wakeword.tflite import WakewordTrigger
90+
from spokestack.asr.spokestack.speech_recognizer import SpeechRecognizer
91+
92+
mic = PyAudioInput()
93+
vad = VoiceActivityDetector()
94+
wake = WakewordTrigger("path_to_tflite_model")
95+
asr = SpeechRecognizer("spokestack_id", "spokestack_secret")
96+
3797

38-
### TFLite Interpreter
98+
pipeline = SpeechPipeline(mic, [vad, wake, asr])
99+
pipeline.start()
100+
pipeline.run()
101+
```
39102

40-
In addition to the Python dependencies, you will need to install the TFLite Interpreter. You can install it for your platform by following the instructions at [TFLite Interpreter](https://www.tensorflow.org/lite/guide/python#install_just_the_tensorflow_lite_interpreter).
41-
**Note:** this is not the full [Tensorflow](https://www.tensorflow.org/) package.
103+
Now that the pipeline is running, it becomes important to access the results from processes at certain events. For example, when speech is recognized there is a `recognize` event. These events allow code to be executed outside the pipeline in response. The process of registering a response is done with a pipeline callback, which we will cover in the next section.
104+
105+
#### Pipeline Callbacks
106+
107+
Pipeline callbacks allow additional code to be executed when a speech event is detected. For example, we can print when the pipeline is activated by registering a function with the `pipeline.event` decorator.
108+
109+
```python
110+
@pipeline.event
111+
def on_activate(context):
112+
print(context.is_active)
113+
```
114+
115+
One of the most important use cases for a pipeline callback is accessing the ASR transcript for additional processing by the NLU. The transcript is accessed with the following:
116+
117+
```python
118+
@pipeline.event
119+
def on_recognize(context):
120+
print(context.transcript)
121+
```
122+
123+
### Natural Language Understanding (NLU)
124+
125+
Natural Language Understanding turns an utterance into structured data a machine can act on. For our purposes, this is joint intent detection and slot filling. You can read more about the concepts [here](https://www.spokestack.io/docs/concepts/nlu). We like to think of intents as the action a user desires from an application, and slots as the optional arguments to fulfill the requested action. Our NLU model is initialized like this:
126+
127+
```python
128+
from spokestack.nlu.tflite import TFLiteNLU
129+
130+
nlu = TFLiteNLU("path_to_tflite_model")
131+
```
132+
133+
Now that the NLU is initialized we can go ahead and add that part to the callback.
134+
135+
```python
136+
@pipeline.event
137+
def on_recognize(context):
138+
results = nlu(context.transcript)
139+
```
140+
141+
### Text To Speech (TTS)
142+
143+
Text To Speech, as the name implies, converts text into spoken audio. This the method for giving your application a voice. We provide one TTS voice for free when you sign up for a Spokestack account, but you can contact us to train a truly custom voice. The TTS API keys are the same as `SpeechRecognizer`. The basic TTS initialization is the following:
144+
145+
```python
146+
from spokestack.tts.manager import TextToSpeechManager
147+
from spokestack.tts.clients.spokestack import TextToSpeechClient
148+
from spokestack.io.pyaudio import PyAudioOutput
149+
150+
client = TextToSpeechClient("spokestack_id", "spokestack_secret")
151+
output = PyAudioOutput()
152+
manager = TextToSpeechManager(client, output)
153+
manager.synthesize("welcome to spokestack")
154+
```
155+
156+
To demonstrate a simple TTS callback let's set up something that reads back what the ASR recognized:
157+
158+
```python
159+
@pipeline.event
160+
def on_recognize(context):
161+
manager.synthesize(context.transcript)
162+
```
42163

43164
## Documentation
44165

45166
### Build the docs
46167

47168
From the root project directory:
48169

49-
cd docs
50-
make clean && make html
170+
```shell
171+
cd docs
172+
make clean && make html
173+
```
51174

52175
## Deployment
53176

54177
This project is distributed using [PyPI](https://pypi.org/). The following is the command to build for installation.
55178

56-
python setup.py clean --all; rm -r ./dist
57-
python setup.py sdist bdist_wheel
179+
```shell
180+
python setup.py clean --all; rm -r ./dist
181+
python setup.py sdist bdist_wheel
182+
```
58183

59184
[Twine](https://twine.readthedocs.io/en/latest/) is used to upload the wheel and source distribution.
60185

61-
twine upload dist/*
186+
```shell
187+
twine upload dist/*
188+
```
62189

63190
## License
64191

65192
Copyright 2020 Spokestack, Inc.
66193

67-
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
68-
69-
http://www.apache.org/licenses/LICENSE-2.0
194+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License [here](http://www.apache.org/licenses/LICENSE-2.0)
70195

71196
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

images/spokestack.png

44.5 KB
Loading

0 commit comments

Comments
 (0)