iflytek/astron-agent · error · BusinessException

AUDIO_DURATION_TOO_LONG

AUDIO_DURATION_TOO_LONG

Error message

AUDIO_DURATION_TOO_LONG

What it means

BusinessException(ResponseEnum.AUDIO_DURATION_TOO_LONG) thrown by validateWavPcmProperties when a WAV/PCM stream's duration (frameLength / frameRate) exceeds MAX_DURATION_SECONDS (40 seconds). The endpoint only accepts short voice clips, so longer WAV PCM audio is rejected after parsing the AudioInputStream.

Solutions

  1. Trim the WAV to 40 seconds or less: ffmpeg -i long.wav -t 39 short.wav.
  2. Split long recordings into multiple <=40s clips and upload them separately.
  3. Record shorter clips at the source (set recorder/assistant max duration to <40s).
  4. Verify the WAV's frameRate header is correct; a corrupt/odd header can inflate computed duration.

Example fix

// before: 90-second clip rejected
upload(clip_90s.wav)
// after: trim to under 40s
// ffmpeg -i clip_90s.wav -t 35 clip_35s.wav
upload(clip_35s.wav)
Defensive patterns

Strategy: validation

Validate before calling

// client-side: estimate duration before upload
const audio = new Audio(URL.createObjectURL(file));
audio.onloadedmetadata = () => { if (audio.duration > 40) alert('Clip must be 40 seconds or shorter'); };

Try / catch

try { AudioValidator.validateAudioProperties(file); }
catch (BusinessException e) { if (ResponseEnum.AUDIO_DURATION_TOO_LONG.equals(e.getResponseEnum())) { /* 400: ask user to trim to <=40s */ } else { throw e; } }

Prevention

When it happens

Trigger: Uploading a WAV/PCM file whose frameLength/frameRate computes to more than 40 seconds — e.g. a 1-minute voice memo — to the audio endpoint that runs validateAudioProperties with WAV-specific checks.

Common situations: Users recording longer messages than the 40s cap; voice assistants trimming endpoints that leak a few extra seconds; uploading full-length songs instead of clips; misconfigured recorder sample rate making duration compute longer than expected.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12). Data as JSON: /api/errors/3c8a6aa1ae2fa4e8. Report an issue: GitHub.

Appendix: source

Thrown at console/backend/commons/src/main/java/com/iflytek/astron/console/commons/util/AudioValidator.java:125

            // For audio files that cannot be parsed, only basic checks are performed
            validateBasicAudioProperties(file);
        }
    }

    /**
     * Validate audio properties for WAV and PCM formats
     */
    private static void validateWavPcmProperties(MultipartFile file) throws IOException, UnsupportedAudioFileException, BusinessException {
        try (AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(file.getInputStream())) {
            AudioFormat format = getAudioFormat(audioInputStream);

            // Check duration (within 40 seconds)
            long frameLength = audioInputStream.getFrameLength();
            float frameRate = format.getFrameRate();
            if (frameRate > 0) {
                float durationSeconds = frameLength / frameRate;
                if (durationSeconds > MAX_DURATION_SECONDS) {
                    throw new BusinessException(ResponseEnum.AUDIO_DURATION_TOO_LONG);
                }
            }
        }
    }

    @NotNull
    private static AudioFormat getAudioFormat(AudioInputStream audioInputStream) {
        AudioFormat format = audioInputStream.getFormat();

        // Check number of channels (mono)
        if (format.getChannels() != REQUIRED_CHANNELS) {
            throw new BusinessException(ResponseEnum.AUDIO_CHANNELS_INVALID);
        }

        // Check sample rate (24kHz and above)
        if (format.getSampleRate() < MIN_SAMPLE_RATE) {
            throw new BusinessException(ResponseEnum.AUDIO_SAMPLE_RATE_TOO_LOW);
        }

View on GitHub (pinned to 5e758547a8)