{"record":{"id":"3c8a6aa1ae2fa4e8","repo":"iflytek/astron-agent","slug":"audio-duration-too-long","errorCode":"AUDIO_DURATION_TOO_LONG","errorMessage":"AUDIO_DURATION_TOO_LONG","messagePattern":"AUDIO_DURATION_TOO_LONG","errorType":"validation","errorClass":"BusinessException","httpStatus":null,"severity":"error","filePath":"console/backend/commons/src/main/java/com/iflytek/astron/console/commons/util/AudioValidator.java","lineNumber":125,"sourceCode":"            // For audio files that cannot be parsed, only basic checks are performed\n            validateBasicAudioProperties(file);\n        }\n    }\n\n    /**\n     * Validate audio properties for WAV and PCM formats\n     */\n    private static void validateWavPcmProperties(MultipartFile file) throws IOException, UnsupportedAudioFileException, BusinessException {\n        try (AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(file.getInputStream())) {\n            AudioFormat format = getAudioFormat(audioInputStream);\n\n            // Check duration (within 40 seconds)\n            long frameLength = audioInputStream.getFrameLength();\n            float frameRate = format.getFrameRate();\n            if (frameRate > 0) {\n                float durationSeconds = frameLength / frameRate;\n                if (durationSeconds > MAX_DURATION_SECONDS) {\n                    throw new BusinessException(ResponseEnum.AUDIO_DURATION_TOO_LONG);\n                }\n            }\n        }\n    }\n\n    @NotNull\n    private static AudioFormat getAudioFormat(AudioInputStream audioInputStream) {\n        AudioFormat format = audioInputStream.getFormat();\n\n        // Check number of channels (mono)\n        if (format.getChannels() != REQUIRED_CHANNELS) {\n            throw new BusinessException(ResponseEnum.AUDIO_CHANNELS_INVALID);\n        }\n\n        // Check sample rate (24kHz and above)\n        if (format.getSampleRate() < MIN_SAMPLE_RATE) {\n            throw new BusinessException(ResponseEnum.AUDIO_SAMPLE_RATE_TOO_LOW);\n        }","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/commons/src/main/java/com/iflytek/astron/console/commons/util/AudioValidator.java#L107-L143","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Trim the WAV to 40 seconds or less: ffmpeg -i long.wav -t 39 short.wav.","Split long recordings into multiple <=40s clips and upload them separately.","Record shorter clips at the source (set recorder/assistant max duration to <40s).","Verify the WAV's frameRate header is correct; a corrupt/odd header can inflate computed duration."],"exampleFix":"// before: 90-second clip rejected\nupload(clip_90s.wav)\n// after: trim to under 40s\n// ffmpeg -i clip_90s.wav -t 35 clip_35s.wav\nupload(clip_35s.wav)","handlingStrategy":"validation","validationCode":"// client-side: estimate duration before upload\nconst audio = new Audio(URL.createObjectURL(file));\naudio.onloadedmetadata = () => { if (audio.duration > 40) alert('Clip must be 40 seconds or shorter'); };","typeGuard":null,"tryCatchPattern":"try { AudioValidator.validateAudioProperties(file); }\ncatch (BusinessException e) { if (ResponseEnum.AUDIO_DURATION_TOO_LONG.equals(e.getResponseEnum())) { /* 400: ask user to trim to <=40s */ } else { throw e; } }","preventionTips":["Enforce a recording-length cap in the capture UI.","Preview duration client-side before upload.","Trim long files with ffmpeg -t before sending.","Document the 40-second limit where users upload voice clips."],"tags":["java","audio","wav","duration-limit"],"backgroundTag":"value-out-of-range","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}