测试采样率

This commit is contained in:
liuwei
2025-05-29 17:53:03 +08:00
parent 243f752800
commit e9334b5133

View File

@@ -339,7 +339,11 @@ class MessageMixin(WechatAPIClientBase):
voice_base64 = base64.b64encode(voice_byte).decode()
elif format.lower() == "wav":
audio = AudioSegment.from_file(BytesIO(voice_byte), format="wav").set_channels(1)
self.logging.debug(f"1audio.frame_rate: {audio.frame_rate}")
audio = audio.set_frame_rate(self._get_closest_frame_rate(audio.frame_rate))
self.logging.debug(f"2audio.frame_rate: {audio.frame_rate}")
logger.info(
f"音频处理: 格式={format}, 采样率={audio.frame_rate}, 声道数={audio.channels}, 时长={len(audio) / 1000}s")
voice_base64 = base64.b64encode(
await pysilk.async_encode(audio.raw_data, sample_rate=audio.frame_rate)).decode()
voice_type = 4