把任意格式转成amr文件
(any_path, amr_path)
| 226 | |
| 227 | |
| 228 | def any_to_amr(any_path, amr_path): |
| 229 | """ |
| 230 | 把任意格式转成amr文件 |
| 231 | """ |
| 232 | if any_path.endswith(".amr"): |
| 233 | shutil.copy2(any_path, amr_path) |
| 234 | return |
| 235 | if any_path.endswith(".sil") or any_path.endswith(".silk") or any_path.endswith(".slk"): |
| 236 | raise NotImplementedError("Not support file type: {}".format(any_path)) |
| 237 | audio = AudioSegment.from_file(any_path) |
| 238 | audio = audio.set_frame_rate(8000) # only support 8000 |
| 239 | audio.export(amr_path, format="amr") |
| 240 | return audio.duration_seconds * 1000 |
| 241 | |
| 242 | |
| 243 | def any_to_mp3(any_path, mp3_path): |