Commit 871b932
authored
fix: detect Tencent SILK (\x02 prefix) in audio magic bytes to avoid ffmpeg failure (#8009)
* fix: detect Tencent SILK (\x02 prefix) in audio magic bytes to avoid ffmpeg failure
QQ official bot sends voice in Tencent SILK format (leading \x02 byte before
#!SILK_V3 magic). _get_audio_magic_type() had two off-by-one slice errors:
1. Standard SILK: header[:8] vs b'#!SILK_V3' (8 != 9 bytes) — never matched
2. Tencent SILK: not detected at all
Fixes:
- Standard SILK: header[:9] == b'#!SILK_V3' (correct 9-byte slice)
- Tencent SILK: header[:1] == b"\x02" and header[1:10] == b'#!SILK_V3'
- ensure_wav() routes detected silk to tencent_silk_to_wav()
Before: QQ voice → ffmpeg → 'Invalid data found'
After: QQ voice → magic detects silk → tencent_silk_to_wav → WAV OK
* refactor: use startswith() for SILK magic byte detection
Replace manual slice comparisons with startswith() — cleaner, less
error-prone, and immune to off-by-one slice errors.
Suggested by: sourcery-ai1 parent c88025c commit 871b932
1 file changed
Lines changed: 15 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
250 | 251 | | |
251 | 252 | | |
252 | 253 | | |
253 | | - | |
| 254 | + | |
| 255 | + | |
254 | 256 | | |
255 | 257 | | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
256 | 265 | | |
257 | 266 | | |
258 | 267 | | |
| |||
291 | 300 | | |
292 | 301 | | |
293 | 302 | | |
294 | | - | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
295 | 308 | | |
296 | 309 | | |
297 | 310 | | |
| |||
0 commit comments