608B71FC-006A-4934-A643-7D9BA9340450Blog

How you can use Scramjet for voice recognition?

blog__author-img

22 July 2022

Our dev team wrote a very easy sample of voice recognition using Scramjet Transform Hub and the speech_recognition Python library. You can use it to change words into a data output for any of your projects with a couple strokes of your keyboard and some copy/paste. The sample needs some external dependencies to run, but we packaged all of them in the sample to limit what you need to install to play around with Scramjet technology.

The first terminal:


_10
# start sth
_10
DEVELOPMENT=1 scramjet-transform-hub

The second terminal:


_10
# go to 'voice-recognition' directory
_10
cd samples/voice-recognition
_10
_10
# install dependencies
_10
yarn build:refapss
_10
_10
# Deploy sample to STH
_10
si seq deploy dist/

Now that you’ve deployed the code, you need to gather the voice and pass it over to the listen.py script, then you can start running the script and start talking!


_16
# You need to pass instane id to listen.py script. Gather it first
_16
si inst ls
_16
[{"id":"da9e41d8-e776-491f-b883-6e61afa93b97","sequence":"15228e0e-b7e3-4008-b4ee-e9aa1d0008d9"}]
_16
_16
# Run listen.py script
_16
SCRAMJET_API_URL="http://localhost:8000/api/v1" INSTANCE_ID="da9e41d8-e776-491f-b883-6e61afa93b97" python3 listen.py
_16
_16
# You should see something similar to this. Now you can start talking :)
_16
http://localhost:8000/api/v1 f5184065-93a0-4a53-96aa-b28ad87801cd
_16
ALSA lib setup.c:547:(add_elem) Cannot obtain info for CTL elem (MIXER,'AC97 2ch->4ch Copy Switch',0,0,0): No such file or directory
_16
ALSA lib pcm.c:2664:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
_16
ALSA lib pcm.c:2664:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
_16
ALSA lib pcm.c:2664:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround21
_16
ALSA lib pcm.c:2664:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround21
_16
ALSA lib setup.c:547:(add_elem) Cannot obtain info for CTL elem (MIXER,'AC97 2ch->4ch Copy Switch',0,0,0): No such file or directory
_16
(...)

Scramjet Transform Hub will recognize your voice (in this instance ‚I like pink elephants’) and provide it as output data in the logs.


_18
2022-07-11T08:12:43.021Z INFO Host List Instances
_18
2022-07-11T08:12:43.021Z DEBUG Host Request [
_18
'date: 2022-07-11T08:12:43.021Z, method: GET, url: /api/v1/instances, status: 200'
_18
]
_18
2022-07-11T08:12:57.366Z INFO PythonRunner Input headers: {'content-type': 'text/plain'}
_18
2022-07-11T08:12:57.366Z DEBUG PythonRunner Decoding input stream...
_18
2022-07-11T08:12:57.366Z DEBUG PythonRunner Input stream forwarded to the instance.
_18
2022-07-11T08:12:57.369Z DEBUG Host Request [
_18
'date: 2022-07-11T08:12:57.365Z, method: POST, url: /input, status: 200'
_18
]
_18
2022-07-11T08:12:58.702Z DEBUG PythonRunner Output type not set, using default
_18
2022-07-11T08:12:58.702Z INFO PythonRunner Output type: text/plain
_18
2022-07-11T08:12:58.702Z DEBUG PythonRunner Output stream will be treated as text and encoded
_18
i like pink elephants 2022-07-11T08:12:59.057Z INFO PythonRunner Finished.
_18
2022-07-11T08:12:59.069Z TRACE ProcessInstanceAdapter Runner process exited [ 10994 ]
_18
2022-07-11T08:12:59.069Z TRACE CSIController Sequence finished with success [ 0 ]
_18
2022-07-11T08:12:59.070Z TRACE Host CSIControlled ended [ 'Exit code: 0' ]
_18
2022-07-11T08:12:59.070Z TRACE CSIController Instance stopped.

Deploying this code takes just a couple keystrokes and is super easy, yet the applications are really broad and can be collected even on a Raspberry Pi somewhere on the edge.

Feel free to use this sample and play around with our technology.

Feel free to check other samples developed by our team in GitHub Platform Samples Repository.

If you like it, consider joining our beta program.

Happy coding!

Project co-financed by the European Union from the European Regional Development Fund under the Knowledge Education Development Program. The project is carried out as a part of the competition of the National for Research and Development: Szybka Ścieżka.