Coder Social home page Coder Social logo

miguelmota / alexa-voice-service.js Goto Github PK

View Code? Open in Web Editor NEW
130.0 11.0 79.0 1.48 MB

Library for interacting with Alexa Voice Service (AVS) in the browser.

Home Page: https://lab.miguelmota.com/alexa-voice-service

License: MIT License

JavaScript 96.47% CSS 0.43% HTML 3.10%
alexa-voice-service audio microphone nodejs avs alexa alexa-skills-kit amazon alexa-app aws

alexa-voice-service.js's Introduction

alexa-voice-service.js

Library for interacting with Alexa Voice Service (AVS) in the browser.


Things you can do

Things you can do with this library:

  • Login with Amazon and get access token
  • Get access token and refresh token from 'code' response type
  • Get access token from refresh token
  • Request user microphone
  • Record user audio using microphone
  • Send user audio to AVS
  • Parse response from AVS
  • Queue and play MP3 responses from AVS.

The audio recorded in this library is mono channel, sampled at 16k Hz, and signed 16 bit PCM encoding which is required by AVS.

Demo

https://lab.miguelmota.com/alexa-voice-service

Install

npm install alexa-voice-service

Example

Follow these steps to run demo locally:

  1. Git clone this repo
git clone [email protected]:miguelmota/alexa-voice-service.js.git

cd alexa-voice-service.js/example/
  1. Install NPM Modules
npm install
  1. Run HTTPS server
npm start
  1. Go to browser url.
open https://localhost:9745

More info in the example README.

Usage

const AVS = require('alexa-voice-service');

const avs = new AVS(options);

Please check out example as noted above.

Documentation

Most methods return a promise.

AVS(options) - constructor

options:
  debug - {boolean} logs to console
  clientId - {string} AVS client id found in portal
  clientSecret - {string} AVS client secret found in portal. Only needed if using `code` response type.
  deviceId - {string} AVS device Id found in portal
  deviceSerialNumber - {number} serial number for this device (can be made up)
  redirectUri - {string} redirect uri set in portal

avs.login({responseType: 'code, token (default)', newWindow: false}) -> promise(response);
avs.promptUserLogin() -> alias to login();
avs.logout() -> promise();
avs.getTokenFromUrl() -> promise(token);
avs.getCodeFromUrl() -> promise(code);
avs.getTokenFromCode(code) -> promise(response);
avs.getTokenFromRefreshToken(refreshToken) -> promise(token)
avs.refreshToken() -> promise({token, refreshToken})
avs.getToken() -> promise(token)
avs.getRefreshToken() -> promise(refreshToken)
avs.requestMic() -> promise(stream);
avs.connectMediaStream(stream) -> promise;
avs.stopRecording() -> promise;
avs.startRecording() -> promise;
avs.sendAudio(dataView) -> promise(response); - send audio to AVS and get back an object containing response.
The response object is the parsed http message.
avs.audioToBlob(AudioBuffer | DataView) -> promise(blob) - mp3 blob

avs.on(identifier, callback)

identifiers (found under AVS.EventTypes object)
  LOG - when a log occurs.
  ERROR - when an error occurs.
  LOGIN - when user is logged in.
  LOGOUT - when user is logged out.
  RECORD_START - when recording is started.
  RECORD_STOP - when recording is stopped.
  TOKEN_SET - when token is set.
  REFRESH_TOKEN_SET - when refresh token is set.
  TOKEN_INVALID - when token is invalid, usually because it is expired.

example: avs.on(AVS.EventTypes.LOG, callback)

// Player

avs.player.enqueue(dataView|typedArray|arrayBuffer|url) -> promise(arraybuffer) - add an audio source to play queue. Converts input to AudioBuffer.
avs.player.deque() -> promise() - dequeu an audio source to play
avs.player.play() -> promise() - play next source in queue
avs.player.stop() -> promise() - stop playing
avs.player.replay() -> promise() - replay last audio source played
avs.player.pause() -> promise() - pause playing
avs.player.emptyQueue() -> promise() - empty the queue
avs.player.playBlob(blob) -> promise(blob) - play a blob source
avs.player.playAudioBuffer(audioBuffer) -> promise() - play an AudioBuffer source
avs.player.playUrl(url) -> promise(url) - play mp3 url

avs.player.on(identifier, callback)

identifiers (found under AVS.Player.EventTypes object)
  LOG - when a debug log occurs
  ERROR - when an error occurs
  PLAY - when audio source is played
  REPLAY - when audio source is replayed
  PAUSE - when audio source is paused
  STOP - when audio source is stopped playing
  ENQUEUE - when an audio source is added to queue
  DEQUE - when an audio source is removed from queue

Resources

License

MIT

alexa-voice-service.js's People

Contributors

linusu avatar miguelmota avatar zamiang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

alexa-voice-service.js's Issues

Problem with Amazon auth

I have an Problem, I installed your git reposetory succesfuel.
And the Website are online. But the error Comes on push the Login butten:

The redirect URI you provided has not been whitelisted for your application. Please add your redirect URI in the 'Allowed Return URLs' section under 'Web Settings' for your Security Profile on Amazon Developer Portal. Request Details client_id=amzn1.application-oa2-client.696ab90fc5844fdbb8efc17394a79c00 scope=alexa%3Aall scope_data=%7B%22alexa%3Aall%22%3A%7B%22productID%22%3A%22test_device%22%2C%22productInstanceAttributes%22%3A%7B%22deviceSerialNumber%22%3A123%7D%7D%7D response_type=token redirect_uri=https://server1.verifybot.de:9745/authresponse

But i have set the right Redirect URL. Show the pictue. https://i.gyazo.com/dfca95094b9c3c4c8e0cb3df0293dcd4.png

Pleas help me.

Custom Skill not getting triggered

Everything is working fine if i ask any question but when i try to trigger my custom skill, it doesn't recognize. My custom skill is working fine on echosim.io. Also i tried from java swing application, i am able to call custom skill.

Error when I clicked on login

python -m SimpleHTTPServer 9000
Serving HTTP on 0.0.0.0 port 9000 ...
127.0.0.1 - - [12/Apr/2016 22:23:40] "GET /example/ HTTP/1.1" 200 -
127.0.0.1 - - [12/Apr/2016 22:23:40] "GET /example/index.css HTTP/1.1" 200 -
127.0.0.1 - - [12/Apr/2016 22:23:40] "GET /example/index.bundle.js HTTP/1.1" 200 -
127.0.0.1 - - [12/Apr/2016 22:23:44] code 400, message Bad request syntax ('\x16\x03\x01\x00\xc2\x01\x00\x00\xbe\x03\x03!L\xd5s\x12\xd9\x862,\xf9{b\x0fF3\xbb\xccw\xbeq\xe7P/)\xd0d\x13\xc9?\x1b\xa7\x00\x00\x1c\xc0+\xc0/\xcc\xa9\xcc\xa8\xcc\x14\xcc\x13\xc0')
127.0.0.1 - - [12/Apr/2016 22:23:44] "??!L?sن2,?{bF3??w?q?P/)?d???+?/̨̩???" 400 -
127.0.0.1 - - [12/Apr/2016 22:23:44] code 400, message Bad HTTP/0.9 request type ('\x16\x03\x01\x00\x99\x01\x00\x00\x95\x03\x02gJ')
127.0.0.1 - - [12/Apr/2016 22:23:44] "??gJ 19?}????-SP???N;qt???.,??" 400 -
127.0.0.1 - - [12/Apr/2016 22:23:44] code 400, message Bad request syntax ('\x16\x03\x01\x00\x99\x01\x00\x00\x95\x03\x01\xc2<5W,\xcd\x0f\xdb\xc4\xb0\xfa\x1d\xd8\x96\xc9\xdd\x9d\xb1\xcd\xfbW\xe5)\xffh\xf7\xbaaS\xe4\xbc\xa9\x00\x00\x10\xc0')
127.0.0.1 - - [12/Apr/2016 22:23:44] "???<5W,??İ?ؖ?ݝ???W?)?h??aS伩?" 400 -

How to control computer through Alexa.

How to control computer through Alexa.

  • open websites
  • open applications
  • pause/play media (if it's in focus)
  • control volume (up, down, mute)
  • run a text search (again, in whatever program is in focus)
  • lock the computer.

Thanks miguel.
I am your fan :)

Amazon returned error upon Authentication?

Hi i followed the mention steps in this repo and i created new product in amazon developer console and i took the client id of that product and i updated on the code. then click on login will navigate to the amazon page after entering all the required details it shows okay or cancel the click on okey it gives me the following error.

We're sorry!
An error occurred when we tried to process your request. Rest assured, we're already working on the problem and expect to resolve it shortly.

I searched in the net some of the links says need to mention the device details but i am unable to see the options as you mentioned in this link.

https://miguelmota.com/blog/alexa-voice-service-authentication/

the options like device type and new device details because i need to pass the device id,serial number for amazon auth request.

please help me to solve this problem.

example not work

Hello,

I have run the example as description in the Readme file.
When I visit the web site, the following error :

net::ERR_EMPTY_RESPONSE

Please help!

Building new example

Thanks for the great project!

example/README.md has an error. There's no build script in package.json, so running npm run build in /examples/ doesn't work.

npm run problem

When I run "npm run watch" under windows, I get this error:

[email protected] watch C:\Users\me\alexa-voice-service.js\example
./node_modules/watchify/bin/cmd.js ./index.js -o ./index.bundle.js -v -d -t [ babelify ]

'.' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] watch: ./node_modules/watchify/bin/cmd.js ./index.js -o ./index.bundle.js -v -d -t [ babelify ]
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] watch script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\me\AppData\Roaming\npm-cache_logs\2018-04-04T17_36_58_864Z-debug.log

Does anyone know what is the problem?
Any help would be much appreciated.

The response message is not played

When a response is received, the player wants to play that but it fails with this error:

Uncaught (in promise) null

I've debugged what was wrong with it, then I saw the problem was in here

https://github.com/miguelmota/alexa-voice-service.js/blob/master/lib/utils/arrayBufferToAudioBuffer.js#L15

and the function has been called from here

return arrayBufferToAudioBuffer(item, this._context)

since there weren't any reject function passed, it's only showing Uncaught in promise error. When I wanted to see the real error on the reject function after implementing it, it wasn't showing me the exact problem.

The response is downloadable, and when you download that you're able to play that file and it contains the correct answer.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.