测试音乐信息
This commit is contained in:
@@ -212,7 +212,7 @@ class MusicPlugin(MessagePluginInterface):
|
|||||||
res = await bot.send_app_message(wxid=receiver, xml=xml_message, type=0)
|
res = await bot.send_app_message(wxid=receiver, xml=xml_message, type=0)
|
||||||
self.LOG.info(f"发送音乐消息 res:{res}")
|
self.LOG.info(f"发送音乐消息 res:{res}")
|
||||||
voice_base64 = await self.url_to_base64(play_url)
|
voice_base64 = await self.url_to_base64(play_url)
|
||||||
res = await bot.send_voice_message(wxid=receiver, voice=voice_base64)
|
res = await bot.send_voice_message(wxid=receiver, voice=voice_base64,format="AMR")
|
||||||
self.LOG.info(f"发送音乐消息 voice res:{res}")
|
self.LOG.info(f"发送音乐消息 voice res:{res}")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|||||||
@@ -320,15 +320,15 @@ class MessageMixin(WechatAPIClientBase):
|
|||||||
raise ValueError("voice should be str, bytes, or path")
|
raise ValueError("voice should be str, bytes, or path")
|
||||||
|
|
||||||
# get voice duration and b64
|
# get voice duration and b64
|
||||||
if format.lower() == "AMR":
|
if format.lower() == "amr":
|
||||||
audio = AudioSegment.from_file(BytesIO(voice_byte), format="amr")
|
audio = AudioSegment.from_file(BytesIO(voice_byte), format="amr")
|
||||||
voice_base64 = base64.b64encode(voice_byte).decode()
|
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 = AudioSegment.from_file(BytesIO(voice_byte), format="wav").set_channels(1)
|
||||||
audio = audio.set_frame_rate(self._get_closest_frame_rate(audio.frame_rate))
|
audio = audio.set_frame_rate(self._get_closest_frame_rate(audio.frame_rate))
|
||||||
voice_base64 = base64.b64encode(
|
voice_base64 = base64.b64encode(
|
||||||
await pysilk.async_encode(audio.raw_data, sample_rate=audio.frame_rate)).decode()
|
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 = AudioSegment.from_file(BytesIO(voice_byte), format="mp3").set_channels(1)
|
||||||
audio = audio.set_frame_rate(self._get_closest_frame_rate(audio.frame_rate))
|
audio = audio.set_frame_rate(self._get_closest_frame_rate(audio.frame_rate))
|
||||||
voice_base64 = base64.b64encode(
|
voice_base64 = base64.b64encode(
|
||||||
@@ -338,7 +338,7 @@ class MessageMixin(WechatAPIClientBase):
|
|||||||
|
|
||||||
duration = len(audio)
|
duration = len(audio)
|
||||||
# Type: AMR = 0, MP3 = 2, SILK = 4, SPEEX = 1, WAVE = 3 VoiceTime :音频长度 1000为一秒
|
# 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",
|
# "Base64": "string",
|
||||||
# "ToWxid": "string",
|
# "ToWxid": "string",
|
||||||
|
|||||||
Reference in New Issue
Block a user