Skip to content
This repository was archived by the owner on Aug 14, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "AudioMaster"
version = "3.2.1"
version = "3.2.2"
description = "一个基于 NoneBot2 的音频转换插件"
authors = [
{name = "KanbeReina", email = "kano.2525@qq.com"},
Expand Down
12 changes: 9 additions & 3 deletions src/AudioMaster/utils/ffmpeg/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import io
from datetime import datetime
from pathlib import Path
from typing import Literal
from typing import Literal, Optional

import nonebot_plugin_localstore as store
from nonebot import get_driver
Expand Down Expand Up @@ -37,6 +37,12 @@ def convert(
io.BytesIO(raw_file) if isinstance(raw_file, bytes) else raw_file
)
audio_format = "flac" if audio_code in (30250, 30251) else "mp3"
# 若为 MP3格式,则指定下载码率
audio_bitrate: Optional[str] = (
None
if audio_format == "flac"
else {30216: "64k", 30232: "132k", 30280: "192k"}.get(audio_code)
)
file_path = store.get_cache_file(
plugin_name="AudioMaster",
filename=f"{AudioHandler._safe_rename(file_name)}.{audio_format}",
Expand All @@ -47,8 +53,8 @@ def convert(
logger.info("对音频进行标准化至 -0.1 dB")
audio = normalize(audio)

logger.info("对音频进行转码")
audio.export(file_path, format=audio_format)
logger.info(f"对音频进行转码(format={audio_format},bitrate={audio_bitrate})")
audio.export(file_path, format=audio_format, bitrate=audio_bitrate)

logger.success(f"处理完成,音频文件已保存至:{file_path}")
return file_path
Expand Down
2 changes: 1 addition & 1 deletion tests/audio/test_handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
@pytest.mark.asyncio(loop_scope="session")
async def test_handle():
audio_path = await BiliManager.audio_handler.convert(
raw_file=FILE_PATH, file_name="UNDEAD(Band ver.)", audio_code="30280"
raw_file=FILE_PATH, file_name="UNDEAD(Band ver.)", audio_code=30280
)
BiliManager.audio_handler.add_music_tags(
audio_path=audio_path, title="UNDEAD", artists="鹿乃", cover=cover
Expand Down