★🔊📖

★经济学

◇经济 / 经济学

◇经济 / 经济学 / 理论

中文书名 英文书名 作者 Book ID
国富论——国民财富的性质和原因 The Wealth of Nations
其它英文名:An Inquiry into the Nature and Causes of the Wealth of Nations
(英) 亚当·斯密 Book 1-5

★军事

◇军事 / 军事理论

中文书名 英文书名 作者 Book ID
孙子兵法
其它中文名:孙武兵法
The Art of War 孙武 Book 6

★政治

◇政治 / 政治小说

中文书名 英文书名 作者 Book ID
一九八四 Nineteen Eighty-Four (英) 乔治·奥威尔 Book 7-9

★制作有声书的脚本

◇下载YouTube视频的mp3

youtube-dl -x --audio-format mp3 --audio-quality 0 "https://www.youtube.com/watch?v=VIDEO_ID"
# yt_mp3_download.py
import subprocess

def download_youtube_mp3():
    yt_dlp_path = "/Users/dev/Library/Python/3.9/bin/yt-dlp"
    url = input("请输入 YouTube 视频链接:").strip()
    
    command = [
        yt_dlp_path,
        "-x",  # 提取音频
        "--audio-format", "mp3",  # 转成 mp3 格式
        url
    ]

    try:
        subprocess.run(command, check=True)
        print("✅ 下载完成")
    except subprocess.CalledProcessError as e:
        print("❌ 下载失败:", e)

if __name__ == "__main__":
    download_youtube_mp3()

◇按对应的章节切割音频

# split_audio.py
import os
import subprocess

input_file = "/Users/dev/Downloads/aaa/xxx.mp3"
output_dir = "output_chapters"
os.makedirs(output_dir, exist_ok=True)

chapters = [
    ("a0", "00:00:00"),
    ("1-chapter1", "00:00:09"),
    ("1-chapter2", "00:39:31"),
    ("2-chapter1", "03:35:20"),
    ("2-chapter2", "04:00:13"),
    ("3-chapter1", "07:48:41"),
    ("3-chapter2", "08:18:27")
]

for i in range(len(chapters)):
    title, start = chapters[i]
    end = chapters[i+1][1] if i+1 < len(chapters) else None

    output_file = os.path.join(output_dir, f"{title}.mp3")
    cmd = ["ffmpeg", "-y", "-i", input_file, "-ss", start]
    if end:
        cmd += ["-to", end]
    cmd += ["-c", "copy", output_file]

    subprocess.run(cmd)
    print(f"导出: {output_file}")

print("全部章节已成功分割。")

◇合并音频

# merge_audio.py
from pydub import AudioSegment
import os

# 设置音频文件夹路径
audio_dir = "/Users/dev/Downloads/aaa/irodori-mp3/X_audio_all"
# 获取所有 mp3 文件,并按文件名排序(可选)
audio_files = sorted([f for f in os.listdir(audio_dir) if f.endswith(".mp3")])

# 创建一个空的音频对象
combined = AudioSegment.empty()

# 逐个添加音频文件
for file in audio_files:
    file_path = os.path.join(audio_dir, file)
    audio = AudioSegment.from_mp3(file_path)
    combined += audio
    print(f"已添加: {file}")

# 导出合成后的音频
output_path = os.path.join(audio_dir, "combined_output.mp3")
combined.export(output_path, format="mp3")
print(f"合成完成,保存为: {output_path}")