mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-11 16:53:49 +00:00
fix(media): recognize MP3 and M4A as voice-compatible audio (#15438)
* fix(media): recognize MP3 and M4A as voice-compatible audio Telegram sendVoice supports OGG/Opus, MP3, and M4A, but isVoiceCompatibleAudio only recognized OGG/Opus formats. - Add MP3 and M4A extensions and MIME types - Use explicit MIME set instead of substring matching - Handle MIME parameters (e.g. 'audio/ogg; codecs=opus') - Add test coverage for all supported and unsupported formats * fix: narrow MIME allowlist per review feedback Remove audio/mp4 and audio/aac from voice MIME types — too broad. Keep only M4A-specific types (audio/x-m4a, audio/m4a). Add audio/mp4 and audio/aac as negative test cases. * fix: align voice compatibility and channel coverage (#15438) (thanks @azade-c) --------- Co-authored-by: Peter Steinberger <steipete@gmail.com>
This commit is contained in:
@@ -1,14 +1,32 @@
|
||||
import { getFileExtension } from "./mime.js";
|
||||
|
||||
const VOICE_AUDIO_EXTENSIONS = new Set([".oga", ".ogg", ".opus"]);
|
||||
const VOICE_AUDIO_EXTENSIONS = new Set([".oga", ".ogg", ".opus", ".mp3", ".m4a"]);
|
||||
|
||||
/**
|
||||
* MIME types compatible with voice messages.
|
||||
* Telegram sendVoice supports OGG/Opus, MP3, and M4A.
|
||||
* https://core.telegram.org/bots/api#sendvoice
|
||||
*/
|
||||
const VOICE_MIME_TYPES = new Set([
|
||||
"audio/ogg",
|
||||
"audio/opus",
|
||||
"audio/mpeg",
|
||||
"audio/mp3",
|
||||
"audio/mp4",
|
||||
"audio/x-m4a",
|
||||
"audio/m4a",
|
||||
]);
|
||||
|
||||
export function isVoiceCompatibleAudio(opts: {
|
||||
contentType?: string | null;
|
||||
fileName?: string | null;
|
||||
}): boolean {
|
||||
const mime = opts.contentType?.toLowerCase();
|
||||
if (mime && (mime.includes("ogg") || mime.includes("opus"))) {
|
||||
return true;
|
||||
const mime = opts.contentType?.toLowerCase().trim();
|
||||
if (mime) {
|
||||
const baseMime = mime.split(";")[0].trim();
|
||||
if (VOICE_MIME_TYPES.has(baseMime)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
const fileName = opts.fileName?.trim();
|
||||
if (!fileName) {
|
||||
|
||||
Reference in New Issue
Block a user