You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Alexa ResumeIntent/PauseIntent返回Null SpeechletResponse错误求助

Fixing Alexa's Null SpeechletResponse Error for Resume/Pause Intents

Hey there, let's break down why you're hitting that Null SpeechletResponse error and fix your ResumeIntent and PauseIntent code step by step:

1. First, Fix Your AMAZON.ResumeIntent Response

Your current ResumeIntent code is missing critical required fields for the AudioPlayer.Play directive, and your shouldEndSession setting isn't ideal for audio skills. Here's the corrected version:

if intent == "AMAZON.ResumeIntent":
    # Tip: Store the paused stream's details (token, URL, offset) in sessionAttributes when pausing
    # This example uses your test values—replace these with actual stored data
    paused_stream = {
        "token": "12345",
        "url": "https://s3.amazonaws.com/jingle.mp3",
        "offsetInMilliseconds": 0  # Use the actual offset saved when paused
    }
    
    return {
        "version": "1.0",
        "sessionAttributes": {},  # Save playback state here for future use
        "response": {
            "outputSpeech": {
                "type": "PlainText",
                "text": "Resuming your audio"
            },
            "directives": [
                {
                    "type": "AudioPlayer.Play",
                    "playBehavior": "REPLACE_ALL",  # Correct behavior for resuming playback
                    "audioItem": {
                        "stream": paused_stream
                    }
                }
            ],
            "shouldEndSession": False  # Keep the session open so users can control playback
        }
    }

Key Fixes:

  • Added playBehavior and audioItem to the AudioPlayer.Play directive—Alexa can't resume playback without knowing which stream to pick up and how to handle it.
  • Set shouldEndSession to False—audio skills need the session open so users can send pause/stop commands mid-playback.
  • Make sure to store the paused stream's offset and token in sessionAttributes when handling PauseIntent, so Resume can pick up exactly where the user left off.

2. Fix Your AMAZON.PauseIntent Response

This is where the Null SpeechletResponse error is likely coming from—your response is missing mandatory top-level fields, uses the wrong AudioPlayer directive, and includes unnecessary parameters. Here's the corrected code:

if intent == "AMAZON.PauseIntent":
    # Get the current playback offset from Alexa's request (you'll need to parse this)
    current_offset = 0  # Replace with actual offset from the request
    
    return {
        "version": "1.0",  # Mandatory top-level field—can't skip this!
        "sessionAttributes": {
            "currentOffset": current_offset,
            "audioToken": "12345"  # Save stream details for ResumeIntent
        },
        "response": {
            "outputSpeech": {
                "type": "PlainText",
                "text": "Paused"
            },
            "directives": [
                {
                    "type": "AudioPlayer.Pause"  # Use Pause, not Stop—Stop clears the playback queue
                }
            ],
            "shouldEndSession": False
        }
    }

Key Fixes:

  • Added the mandatory version and sessionAttributes top-level fields—Alexa requires these in every response, even if sessionAttributes is empty. Missing them causes the Null SpeechletResponse error directly.
  • Swapped AudioPlayer.Stop for AudioPlayer.Pause: Stop is for ending playback entirely and clearing the queue, while Pause is for pausing temporarily so users can resume later.
  • Removed unnecessary playBehavior and audioItem fields—AudioPlayer.Pause doesn't need these, and extra invalid fields will break the response.
  • Stored the current playback offset in sessionAttributes so ResumeIntent can pick up where things left off.

Quick General Tips

  • Always validate your response against Alexa's official response schema—missing mandatory fields or including invalid parameters is the #1 cause of Null SpeechletResponse errors.
  • When testing, use the Alexa Developer Console's test panel first—it shows detailed request/response logs that make it easy to spot missing fields or invalid directives, which is way faster than testing only on a Fire tablet.
  • For audio skills, keep shouldEndSession set to False during playback so users can control audio without re-invoking the skill.

内容的提问来源于stack exchange,提问作者Jonathan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 06:40:19