feat(wechatcom): add support for sending voice messages

This commit is contained in:
lanvent
2023-04-20 01:46:23 +08:00
parent 4cbf46fd4d
commit ab83dacb76
3 changed files with 49 additions and 6 deletions

View File

@@ -69,6 +69,24 @@ def any_to_sil(any_path, sil_path):
raise NotImplementedError("Not support file type: {}".format(any_path))
def any_to_amr(any_path, amr_path):
"""
把任意格式转成amr文件
"""
if any_path.endswith(".amr"):
shutil.copy2(any_path, amr_path)
return
if (
any_path.endswith(".sil")
or any_path.endswith(".silk")
or any_path.endswith(".slk")
):
raise NotImplementedError("Not support file type: {}".format(any_path))
audio = AudioSegment.from_file(any_path)
audio = audio.set_frame_rate(8000) # only support 8000
audio.export(amr_path, format="amr")
def mp3_to_wav(mp3_path, wav_path):
"""
把mp3格式转成pcm文件