Closed greggmojica closed 7 years ago
Hi Gregg, did you see these docs here? http://docs.bespoken.tools/en/latest/api/classes/bstencode.html
The encoder automatically encodes the file and uploads it to an S3 bucket that you designate. Hope it makes sense, and let me know if you have more questions.
@jkelvie, I did see the docs, but they're short on any examples (which is problematic and I'd love to update them with a PR once I know how to use the module).
Basically, I have a mp3 file hosted (with s3 url), it needs to be converted to the exact format that alexa requires, do you have an example of the source code to do this? Thank you very much!
Hi Gregg, sorry that the docs are not more helpful. You are right that they could certainly use some more examples.
Here is a repo we have the uses the encoder. It gets initialized and configured here: https://github.com/bespoken/streamer/blob/master/lib/audioConverter.js#L10
The encoder config tells it what bucket to upload files to as well as provides AWS credentials for accessing the bucket.
Then the call to encode happens here: https://github.com/bespoken/streamer/blob/master/lib/audioConverter.js#L31
This takes a URL (the input file) and a name (the name is what the converted file should be called in the bucket), and calls back with the URL of the uploaded file on S3.
There are alternative routines that will take a file (as opposed to a URL), as well as the option to not specify a name (encodeURLAndPublish as opposed to encodeURLAndPublishAs). In the case where a name is not specified, it will just take the last part of the path from the URL.
All the files are automatically converted to the correct format for Alexa.
I hope that helps - let me know how it goes.
-John
On Mon, Sep 11, 2017 at 6:30 PM Gregg Mojica notifications@github.com wrote:
@jkelvie https://github.com/jkelvie, I did see the docs, but they're short on any examples (which is problematic and I'd love to update them with a PR once I know how to use the module).
Basically, I have a mp3 file hosted (with s3 url), it needs to be converted to the exact format that alexa requires, do you have an example of the source code to do this? Thank you very much!
— You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub https://github.com/bespoken/bst/issues/380#issuecomment-328687276, or mute the thread https://github.com/notifications/unsubscribe-auth/AABDc3zOc4uCiXcwzKrSQNyqYAGhG2PNks5shcJ6gaJpZM4PT2gN .
@jkelvie thank you for your reply. Very helpful. perhaps I am missing something here, but I was able to come across this code snippet from one of your teammates on stackoverflow:
var bst = require("bespoken-tools");
var encoder = new BSTEncode({ bucket: "xxxxxxxxxxx" });
encoder.encodeURLAndPublish("https://xxxxxxxxxxxxxxxxxx.mp3");
However, this code fails with "BSTEncode is not a constructor". Am I not importing something? Thanks for your help!
Hi, I put that example on StackOverflow! But it has a typo.
The correct code should be:
var bst = require("bespoken-tools");
var encoder = new bst.BSTEncode({ bucket: "S3Bucket" });
encoder.encodeURLAndPublish("https://s3.amazonaws.com/alexa-files/my-raw-file.wav");
In particular, it needs to be: new bst.BSTEncode(...)
not new BSTEncode(...)
.
I updated the entry on StackOverflow to reflect that - thanks for bringing to my attention 👍
@jkelvie thanks so much! I updated the snippet but I'm getting this error now. Any thoughts?
node_modules/bespoken-tools/lib/client/bst-encode.js:35
callback(error, encodedURL);
^
TypeError: callback is not a function
Hi, sorry, I should never share code snippets that are not from working code. The issue is that example also does not include a callback function. That should be passed as the second parameter to the encode call.
-John
On Mon, Sep 11, 2017, 6:59 PM Gregg Mojica notifications@github.com wrote:
@jkelvie https://github.com/jkelvie thanks so much! I updated the snippet but I'm getting this error now. Any thoughts? node_modules/bespoken-tools/lib/client/bst-encode.js:35 callback(error, encodedURL); ^ TypeError: callback is not a function
— You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub https://github.com/bespoken/bst/issues/380#issuecomment-328691781, or mute the thread https://github.com/notifications/unsubscribe-auth/AABDc73SOy9BKp-YEBEjnaNN8P_TJjbXks5shcl5gaJpZM4PT2gN .
@jkelvie, I updated it with this but it is returning NULL. Thoughts?
var bst = require("bespoken-tools");
var encoder = new bst.BSTEncode({ accessKeyId: "XXXXXXX", secretAccessKey: "XXXXXXXXXXX", bucket: "XXXXXXXX" });
encoder.encodeURLAndPublish("https://XXXXXXXXXXXXXXXXXX.mp3", function(s) {
console.log(s);
});
The first parameter to the callback is the error (if any), the second is the URL of the encoded file. So null is good!
-John
On Mon, Sep 11, 2017, 7:10 PM Gregg Mojica notifications@github.com wrote:
@jkelvie https://github.com/jkelvie, I updated it with this but it is returning NULL. Thoughts? var bst = require("bespoken-tools"); var encoder = new bst.BSTEncode({ accessKeyId: "XXXXXXX", secretAccessKey: "XXXXXXXXXXX", bucket: "XXXXXXXX" }); encoder.encodeURLAndPublish("https://XXXXXXXXXXXXXXXXXX.mp3", function(s) { console.log(s); });
— You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub https://github.com/bespoken/bst/issues/380#issuecomment-328693435, or mute the thread https://github.com/notifications/unsubscribe-auth/AABDc_60cXlLULM2JccRj6F9rbq3VZTtks5shcwRgaJpZM4PT2gN .
It works! Thank you for all your help!!!
How do I use BSTEncode for alexa mp3?