0

I'm currently new into nodejs, but I've been trying to make an Alexa Skill using the Nodejs Trivia Sample provided on GitHub.

Nothing has been modified in the code, just the content (questions). The change is, instead of Question (words), I would like to to play Audio MP3. That should/is possible using SSML Audio

I tried to do that, but my Skill wouldn't work that way, won't even start.

Here's original sample:

{
   'What Makes Santa\'s Reindeer Fly?': [
      'Magical Reindeer Dust',
      'Fusion',
      'Amanita muscaria',
      'Elves',
   ],
},

What I did, using the Audio SSML:

{
   '<audio src="link_to_the.mp3' />": [
      'Magical Reindeer Dust',
      'Fusion',
      'Amanita muscaria',
      'Elves',
   ],
},

The github source: https://github.com/alexa/skill-sample-nodejs-trivia/tree/en-US/lambda/custom

What am I doing wrong here? It's supposed to work, right?

Tudor
  • 7
  • 3
  • What do you mean by `Skill won't work, won't even start'? How did you verify that skill didn't launch? If you are using Lambda, did you check the Lambda CloudWatch logs? – Chacko Dec 18 '17 at 10:38
  • I simply ask my Alexa Device to open the Skill and it won't launch, instead will throw an error. Weird, if I put the Audo SSML Tag inside the index.js, it works, but not in the "const question" @ChackoMathew – Tudor Dec 18 '17 at 11:56
  • @ChackoMathew The CloudWatch Error: https://www.dropbox.com/s/46j63zql4xys8ru/error_ssml.png – Tudor Dec 18 '17 at 11:59
  • @ChackoMathew It's not a mistake while copying. Tried also the way you told me and different ways (with space, with " and ') and is the same. I think it has to do with the new way of importing the questions? The error I'm seeing is "Unexpected exception "TypeError: Cannot assign to read only property '60' of string 'blabla.mp3' ". Do you know what I mean? – Tudor Dec 18 '17 at 17:23

1 Answers1

1

Please check your audio length(The audio file cannot be longer than ninety (90) seconds) and make sure you have converted the mp3 to correct format.

I hope you have gone through this documentation - Using Audio in Your Response

Edit:- Hey, I just tried and found a solution.

  1. In the question.js file add mp3 links alone to the questions.

{ 'https://mp3_link': [ 'Magical Reindeer Dust', 'Fusion', 'Amanita muscaria', 'Elves', ], },

  1. In the index.js file, find the variable named "spokenquestion" and add the audio tag to it. Find example below

      const spokenQuestion = '<audio src="'+Object.keys(translatedQuestions[gameQuestions[currentQuestionIndex]])[0]+'" />';
    

Note: This will only work when you include the mp3 link to all the questions. If some questions have mp3 links and some questions have text then please add conditions accordingly. Find sample example below

 if(question.substring have https) then audio else text

Edit 2 : 1.Add audio file name in the question.

{ 'name_of_the _audio_file': [ 'Magical Reindeer Dust', 'Fusion', 'Amanita muscaria', 'Elves', ], },

2.Add audio link in the audio tag

const spokenQuestion = '<audio src="https://s3.amazonaws.com/s3_bucket_name/'+Object.keys(translatedQuestions[gameQuestions[currentQuestionIndex]])[0]+'.mp3" />';
Kannan
  • 194
  • 10
  • Thank you, but the audio length and format is correctly set. – Tudor Dec 18 '17 at 12:00
  • Edited my answer – Kannan Dec 18 '17 at 17:27
  • Thank you for that, but it still doesn't seem to work. I modified what you told me exactly in 2 places (line 221 and line 260) in https://github.com/alexa/skill-sample-nodejs-trivia/blob/en-US/lambda/custom/index.js ; and the question.js now has just the mp3 links. It still won't start the skill. Did you test it? Did it work for you? – Tudor Dec 18 '17 at 18:32
  • Please share your full code. I have tested it and the skill launched and audio played successfully. – Kannan Dec 18 '17 at 20:19
  • Sure, https://pastebin.com/t6AwnJJw Thank you. It's just the original one, but with the German language only. Or maybe it would be better if you send me your index source? @Kannan – Tudor Dec 18 '17 at 20:55
  • Find the working code here - https://github.com/kannansantharam/alexa-trivia-with-audio . Audio will play but it has some issues, I will work on it later or you can try to solve it and post the solution here. You will face the issue after the audio end. – Kannan Dec 19 '17 at 04:16
  • Yes, tested the code you sent me, it works, but the answers/options are not working @kannan Thanks! – Tudor Dec 19 '17 at 06:46
  • Yes, that's the issue. I think it is an indexing problem. Please check it. – Kannan Dec 19 '17 at 06:49
  • No, Didn't modify anything for the answers. Please let me know if you can find the solution for this issue. (I will work on it after 8 hours). – Kannan Dec 19 '17 at 07:06
  • I didn't find the cause of it. Did you? – Tudor Dec 20 '17 at 15:47
  • Hey, not getting enough time to work on it. But fixed the "answers/options not working" issue and committed the latest code in my github. Changes: 1. You need to just add the audio name alone in the question. (make sure your audio name does not have any special characters) . 2. Add the audio link in the audio tag. – Kannan Dec 21 '17 at 14:51
  • Thank you, I'll test it and get back to you. Is there any way I could get in touch with you privately? – Tudor Dec 22 '17 at 15:42
  • I will message you on facebook shortly. – Kannan Dec 22 '17 at 15:48