11package me .yun .silk .utils ;
22
33import me .yun .silk .SilkCodec ;
4+ import me .yun .silk .AacCodec ;
45
56public class Conversion {
67
78 public interface ConversionCallback {
89 void onMessage (String msg );
10+ default void onProgress (int progress ) {}
911 }
1012
1113 public static void startTransform (SilkCodec codec , int type , String inputPath , String outputPath , int sampleRate , ConversionCallback callback ) {
@@ -20,6 +22,9 @@ public static void startTransform(SilkCodec codec, int type, String inputPath, S
2022 case 1 : result = codec .mp3ToSilk (inputPath , outputPath , sampleRate ); break ;
2123 case 5 : result = codec .autoToSilk (inputPath , outputPath , sampleRate ); break ;
2224 case 6 : result = codec .autoToPcm (inputPath , outputPath ); break ;
25+ case 7 : result = AacCodec .autoToAac (inputPath , outputPath , codec , sampleRate ); break ;
26+ case 8 : result = AacCodec .autoToM4a (inputPath , outputPath , codec , sampleRate ); break ;
27+ case 9 : result = AacCodec .m4aToSilk (inputPath , outputPath , codec , sampleRate ); break ;
2328 }
2429
2530 if (result == 0 ) {
@@ -33,6 +38,46 @@ public static void startTransform(SilkCodec codec, int type, String inputPath, S
3338 }).start ();
3439 }
3540
41+ public static int silkToAac (SilkCodec codec , String silkPath , String aacPath , int hz ) {
42+ return AacCodec .silkToAac (silkPath , aacPath , codec , hz );
43+ }
44+
45+ public static int silkToM4a (SilkCodec codec , String silkPath , String m4aPath , int hz ) {
46+ return AacCodec .silkToM4a (silkPath , m4aPath , codec , hz );
47+ }
48+
49+ public static int mp3ToAac (String mp3Path , String aacPath , int sampleRate ) {
50+ return AacCodec .mp3ToAac (mp3Path , aacPath , sampleRate );
51+ }
52+
53+ public static int mp3ToM4a (String mp3Path , String m4aPath , int sampleRate ) {
54+ return AacCodec .mp3ToM4a (mp3Path , m4aPath , sampleRate );
55+ }
56+
57+ public static int wavToAac (String wavPath , String aacPath , int sampleRate ) {
58+ return AacCodec .wavToAac (wavPath , aacPath , sampleRate );
59+ }
60+
61+ public static int wavToM4a (String wavPath , String m4aPath , int sampleRate ) {
62+ return AacCodec .wavToM4a (wavPath , m4aPath , sampleRate );
63+ }
64+
65+ public static int m4aToSilk (SilkCodec codec , String m4aPath , String silkPath , int hz ) {
66+ return AacCodec .m4aToSilk (m4aPath , silkPath , codec , hz );
67+ }
68+
69+ public static int m4aToPcm (String m4aPath , String pcmPath ) {
70+ return AacCodec .m4aToPcm (m4aPath , pcmPath );
71+ }
72+
73+ public static int pcmToAac (String pcmPath , String aacPath , int sampleRate , int channels ) {
74+ return AacCodec .pcmToAac (pcmPath , aacPath , sampleRate , channels );
75+ }
76+
77+ public static int pcmToM4a (String pcmPath , String m4aPath , int sampleRate , int channels ) {
78+ return AacCodec .pcmToM4a (pcmPath , m4aPath , sampleRate , channels );
79+ }
80+
3681 private static String getFileTypeName (int type ) {
3782 switch (type ) {
3883 case 1 : return "Silk" ;
@@ -66,7 +111,17 @@ private static String getErrorMsg(int code) {
66111 case -501 : case -502 : return "错误码:" + code + " → WAV 解码错误" ;
67112 case -601 : case -602 : return "错误码:" + code + " → FLAC 解码错误" ;
68113 case -701 : case -702 : case -703 : return "错误码:" + code + " → PCM 参数错误" ;
114+ case -801 : case -802 : return "错误码:" + code + " → AAC/M4A 解码错误 (文件读取失败)" ;
115+ case -803 : return "错误码:-803 → AAC/M4A 解码错误 (格式不支持)" ;
116+ case -901 : case -902 : return "错误码:" + code + " → AAC/M4A 编码错误" ;
117+ case -911 : case -912 : return "错误码:" + code + " → M4A 编码错误" ;
118+ case -1001 : return "错误码:-1001 → Silk 转 AAC/M4A 错误" ;
119+ case -1011 : case -1012 : return "错误码:" + code + " → MP3 转 AAC/M4A 错误" ;
120+ case -1021 : case -1022 : return "错误码:" + code + " → WAV 转 AAC/M4A 错误" ;
121+ case -1031 : return "错误码:-1031 → AAC/M4A 转 Silk 错误" ;
122+ case -1041 : return "错误码:-1041 → 中间转换错误" ;
123+ case -2000 : return "错误码:-2000 → M4A/AAC 转 Silk 错误 (解码失败)" ;
69124 default : return "错误码:" + code + " → 未知错误" ;
70125 }
71126 }
72- }
127+ }
0 commit comments