4

I am trying to play an audio file through Alexa. My backend in Ruby on Rails and I am using alexa-ruby gem.

I was able to produce speeches via ask and tell directive like this

def index
    parsed_request = JSON.parse(request.body.read)
    alexa = AlexaRuby.new(parsed_request)
    speech = "Hey there! I am alexa"
    response = alexa.response.ask!(speech)
    render json: response
end

When I tried to play audio, I am getting no response. This is what I tried to do

def index
    parsed_request = JSON.parse(request.body.read)
    alexa = AlexaRuby.new(parsed_request)
    params = { url: 'https://s3.amazonaws.com/my-ssml-samples/Flourish.mp3', token: 'flourish-token', offset: 0 }
    response = alexa.response.add_audio_player_directive(:start, params)
    render json: response
end
Nidhin S G
  • 1,685
  • 2
  • 15
  • 45
  • what are the errors? – johndoe Aug 08 '18 at 11:34
  • well the errors shown in json response is this, which is pretty much straight.. So i don't think its helpfull '"error"=>{"type"=>"INVALID_RESPONSE", "message"=>"An exception occurred while dispatching the request to the skill."}}}}' – Nidhin S G Aug 08 '18 at 11:38
  • 3
    When asking how to fix an error, knowing the error is a critical, probably most important thing that needs stated. You may want to expand a little more on that aspect in the actual question, such as EXACT error, what line, relevant context, etc. – ForeverZer0 Aug 08 '18 at 11:48
  • okay, my mistake, actually there is no response.. and the reason for no response shown in json was this "error"=>{"type"=>"INVALID_RESPONSE", "message"=>"An exception occurred while dispatching the request to the skill."}}}} – Nidhin S G Aug 09 '18 at 03:30

1 Answers1

1

So depending on the type of audio you are trying to play you may want to try a different strategy. The audio player directive is more for playing something like a stream and gives the pause, rewind, etc type controls. It would be used if you where creating a music player or playing a long format audio file like a podcast.

From you example it looks like you are just trying to play a simple mp3. You can do this with the exact same way you did the speech using SSML.

For Example:

def index
parsed_request = JSON.parse(request.body.read)
alexa = AlexaRuby.new(parsed_request)
speech = "<speak>
  Welcome to Ride Hailer. 
  <audio     src="soundbank://soundlibrary/transportation/amzn_sfx_car_accelerate_01" /> 
You can order a ride, or request a fare estimate. 
Which will it be?</speak>" 
response = alexa.response.ask!(speech)
render json: response
end

You can find additional info here

https://developer.amazon.com/en-US/docs/alexa/custom-skills/speech-synthesis-markup-language-ssml-reference.html

AhDev
  • 486
  • 11
  • 16