测试音乐信息

This commit is contained in:
liuwei
2025-05-26 15:02:57 +08:00
parent 44be041eac
commit 25a847da10
2 changed files with 5 additions and 5 deletions

View File

@@ -320,15 +320,15 @@ class MessageMixin(WechatAPIClientBase):
raise ValueError("voice should be str, bytes, or path")
# get voice duration and b64
if format.lower() == "AMR":
if format.lower() == "amr":
audio = AudioSegment.from_file(BytesIO(voice_byte), format="amr")
voice_base64 = base64.b64encode(voice_byte).decode()
elif format.lower() == "WAVE":
elif format.lower() == "wave":
audio = AudioSegment.from_file(BytesIO(voice_byte), format="wav").set_channels(1)
audio = audio.set_frame_rate(self._get_closest_frame_rate(audio.frame_rate))
voice_base64 = base64.b64encode(
await pysilk.async_encode(audio.raw_data, sample_rate=audio.frame_rate)).decode()
elif format.lower() == "MP3":
elif format.lower() == "mp3":
audio = AudioSegment.from_file(BytesIO(voice_byte), format="mp3").set_channels(1)
audio = audio.set_frame_rate(self._get_closest_frame_rate(audio.frame_rate))
voice_base64 = base64.b64encode(
@@ -338,7 +338,7 @@ class MessageMixin(WechatAPIClientBase):
duration = len(audio)
# Type AMR = 0, MP3 = 2, SILK = 4, SPEEX = 1, WAVE = 3 VoiceTime :音频长度 1000为一秒
format_dict = {"AMR": 0, "WAVE": 3, "MP3": 2, "SILK": 4, "SPEEX": 1}
format_dict = {"amr": 0, "wave": 3, "mpe3": 2, "silk": 4, "speex": 1}
# {
# "Base64": "string",
# "ToWxid": "string",