podcast-splitter

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Podcast Splitter

播客分割工具

Automatically split audio files into segments based on silence detection. Perfect for dividing podcasts into chapters, creating clips from long recordings, or removing dead air.
基于静音检测自动将音频文件分割为多个片段。非常适合将播客划分为章节、从长录音中创建片段或移除空白静音部分。

Quick Start

快速开始

python
from scripts.podcast_splitter import PodcastSplitter
python
from scripts.podcast_splitter import PodcastSplitter

Auto-split by silence

按静音自动分割

splitter = PodcastSplitter("podcast_episode.mp3") segments = splitter.split_by_silence() splitter.export_segments("./chapters/")
splitter = PodcastSplitter("podcast_episode.mp3") segments = splitter.split_by_silence() splitter.export_segments("./chapters/")

Remove long silences

移除长静音

splitter = PodcastSplitter("raw_recording.mp3") splitter.remove_silence(min_length=2000) # Remove silences > 2 seconds splitter.save("clean_recording.mp3")
undefined
splitter = PodcastSplitter("raw_recording.mp3") splitter.remove_silence(min_length=2000) # 移除时长超过2秒的静音 splitter.save("clean_recording.mp3")
undefined

Features

功能特性

  • Silence Detection: Configurable threshold and duration
  • Auto-Split: Divide audio at natural breaks
  • Silence Removal: Remove or shorten long pauses
  • Chapter Export: Save individual segments as files
  • Preview Mode: List detected silences without splitting
  • Batch Processing: Process multiple files
  • 静音检测:可配置阈值和时长
  • 自动分割:在自然停顿处分割音频
  • 静音移除:移除或缩短长停顿
  • 章节导出:将单个片段保存为文件
  • 预览模式:列出检测到的静音而不进行分割
  • 批量处理:处理多个文件

API Reference

API 参考

Initialization

初始化

python
splitter = PodcastSplitter("audio.mp3")
python
splitter = PodcastSplitter("audio.mp3")

With custom settings

自定义设置

splitter = PodcastSplitter( "audio.mp3", silence_thresh=-40, # dBFS threshold min_silence_len=1000, # Minimum silence length (ms) keep_silence=300 # Silence to keep at segment edges (ms) )
undefined
splitter = PodcastSplitter( "audio.mp3", silence_thresh=-40, # dBFS阈值 min_silence_len=1000, # 最小静音时长(毫秒) keep_silence=300 # 片段边缘保留的静音时长(毫秒) )
undefined

Silence Detection

静音检测

python
undefined
python
undefined

Detect silence regions

检测静音区域

silences = splitter.detect_silence()
silences = splitter.detect_silence()

Returns: [(start_ms, end_ms), (start_ms, end_ms), ...]

返回:[(开始毫秒, 结束毫秒), (开始毫秒, 结束毫秒), ...]

Print silence summary

打印静音摘要

splitter.print_silence_report()
undefined
splitter.print_silence_report()
undefined

Splitting

分割操作

python
undefined
python
undefined

Split at all detected silences

在所有检测到的静音处分割

segments = splitter.split_by_silence()
segments = splitter.split_by_silence()

Split at silences longer than threshold

在长于指定时长的静音处分割

segments = splitter.split_by_silence(min_silence_len=3000)
segments = splitter.split_by_silence(min_silence_len=3000)

Limit number of segments

限制片段数量

segments = splitter.split_by_silence(max_segments=10)
undefined
segments = splitter.split_by_silence(max_segments=10)
undefined

Silence Removal

静音移除

python
undefined
python
undefined

Remove silences longer than threshold

移除长于指定时长的静音

splitter.remove_silence(min_length=2000) # Remove >2s silences
splitter.remove_silence(min_length=2000) # 移除时长>2秒的静音

Shorten silences to max length

将静音缩短至最大时长

splitter.shorten_silence(max_length=500) # Cap at 500ms
splitter.shorten_silence(max_length=500) # 静音时长上限为500毫秒

Remove leading/trailing silence only

仅移除开头/结尾的静音

splitter.strip_silence()
undefined
splitter.strip_silence()
undefined

Export

导出操作

python
undefined
python
undefined

Export all segments

导出所有片段

splitter.export_segments( output_dir="./chapters/", prefix="chapter", # chapter_01.mp3, chapter_02.mp3 format="mp3", bitrate=192 )
splitter.export_segments( output_dir="./chapters/", prefix="chapter", # 输出文件名示例:chapter_01.mp3, chapter_02.mp3 format="mp3", bitrate=192 )

Export specific segments

导出指定片段

splitter.export_segment(0, "intro.mp3") splitter.export_segment(3, "conclusion.mp3")
splitter.export_segment(0, "intro.mp3") splitter.export_segment(3, "conclusion.mp3")

Save modified audio

保存修改后的音频

splitter.save("output.mp3")
undefined
splitter.save("output.mp3")
undefined

CLI Usage

命令行界面使用方法

bash
undefined
bash
undefined

Split podcast into chapters

将播客分割为章节

python podcast_splitter.py --input episode.mp3 --output-dir ./chapters/
python podcast_splitter.py --input episode.mp3 --output-dir ./chapters/

Detect and list silences (no splitting)

检测并列出静音(不进行分割)

python podcast_splitter.py --input episode.mp3 --detect-only
python podcast_splitter.py --input episode.mp3 --detect-only

Remove long silences

移除长静音

python podcast_splitter.py --input raw.mp3 --output clean.mp3 --remove-silence 2000
python podcast_splitter.py --input raw.mp3 --output clean.mp3 --remove-silence 2000

Custom sensitivity

自定义灵敏度

python podcast_splitter.py --input episode.mp3 --output-dir ./chapters/
--threshold -35 --min-silence 2000 --keep-silence 500
undefined
python podcast_splitter.py --input episode.mp3 --output-dir ./chapters/
--threshold -35 --min-silence 2000 --keep-silence 500
undefined

CLI Arguments

命令行参数

ArgumentDescriptionDefault
--input
Input audio fileRequired
--output
Output file (for silence removal)-
--output-dir
Output directory for segments-
--detect-only
Only detect/report silencesFalse
--threshold
Silence threshold (dBFS)-40
--min-silence
Minimum silence to detect (ms)1000
--keep-silence
Silence to keep at edges (ms)300
--max-segments
Maximum segments to createNone
--remove-silence
Remove silences longer than (ms)-
--shorten-silence
Cap silence length at (ms)-
--prefix
Output filename prefixsegment
--format
Output formatmp3
--bitrate
Output bitrate (kbps)192
参数描述默认值
--input
输入音频文件必填
--output
输出文件(用于静音移除)-
--output-dir
片段输出目录-
--detect-only
仅检测/报告静音
--threshold
静音阈值(dBFS)-40
--min-silence
检测的最小静音时长(毫秒)1000
--keep-silence
片段边缘保留的静音时长(毫秒)300
--max-segments
最大片段数量
--remove-silence
移除长于该时长的静音(毫秒)-
--shorten-silence
静音时长上限(毫秒)-
--prefix
输出文件名前缀segment
--format
输出格式mp3
--bitrate
输出比特率(kbps)192

Examples

示例

Split Interview into Q&A Segments

将访谈分割为问答片段

python
splitter = PodcastSplitter(
    "interview.mp3",
    silence_thresh=-35,     # Less sensitive (louder threshold)
    min_silence_len=2000,   # Only split on 2+ second pauses
    keep_silence=400        # Keep some silence for natural feel
)

segments = splitter.split_by_silence()
print(f"Found {len(segments)} segments")

splitter.export_segments("./questions/", prefix="qa")
python
splitter = PodcastSplitter(
    "interview.mp3",
    silence_thresh=-35,     # 灵敏度较低(阈值更高)
    min_silence_len=2000,   # 仅在静音时长≥2秒处分割
    keep_silence=400        # 保留少量静音以保证自然感
)

segments = splitter.split_by_silence()
print(f"检测到 {len(segments)} 个片段")

splitter.export_segments("./questions/", prefix="qa")

Remove Dead Air from Recording

从录音中移除空白静音

python
splitter = PodcastSplitter("raw_recording.mp3")
python
splitter = PodcastSplitter("raw_recording.mp3")

Show what would be removed

查看将被移除的静音

splitter.print_silence_report()
splitter.print_silence_report()

Remove silences longer than 3 seconds

移除时长超过3秒的静音

splitter.remove_silence(min_length=3000)
splitter.remove_silence(min_length=3000)

Cap remaining silences at 1 second

将剩余静音时长限制为1秒

splitter.shorten_silence(max_length=1000)
splitter.save("clean_recording.mp3")
undefined
splitter.shorten_silence(max_length=1000)
splitter.save("clean_recording.mp3")
undefined

Create Highlight Clips

创建精彩片段

python
splitter = PodcastSplitter("episode.mp3")
segments = splitter.split_by_silence(min_silence_len=5000)
python
splitter = PodcastSplitter("episode.mp3")
segments = splitter.split_by_silence(min_silence_len=5000)

Export only segments longer than 30 seconds

仅导出时长超过30秒的片段

for i, segment in enumerate(segments): duration = segment['end'] - segment['start'] if duration > 30000: # > 30 seconds splitter.export_segment(i, f"highlight_{i+1}.mp3")
undefined
for i, segment in enumerate(segments): duration = segment['end'] - segment['start'] if duration > 30000: # > 30秒 splitter.export_segment(i, f"highlight_{i+1}.mp3")
undefined

Batch Process Episodes

批量处理播客剧集

python
import os
from scripts.podcast_splitter import PodcastSplitter

episodes_dir = "./raw_episodes/"
output_dir = "./processed/"

for filename in os.listdir(episodes_dir):
    if filename.endswith('.mp3'):
        filepath = os.path.join(episodes_dir, filename)
        splitter = PodcastSplitter(filepath)

        # Remove long silences
        splitter.remove_silence(min_length=2000)

        # Save cleaned version
        output_path = os.path.join(output_dir, filename)
        splitter.save(output_path)
        print(f"Processed: {filename}")
python
import os
from scripts.podcast_splitter import PodcastSplitter

episodes_dir = "./raw_episodes/"
output_dir = "./processed/"

for filename in os.listdir(episodes_dir):
    if filename.endswith('.mp3'):
        filepath = os.path.join(episodes_dir, filename)
        splitter = PodcastSplitter(filepath)

        # 移除长静音
        splitter.remove_silence(min_length=2000)

        # 保存处理后的版本
        output_path = os.path.join(output_dir, filename)
        splitter.save(output_path)
        print(f"已处理:{filename}")

Preview Silence Detection

预览静音检测结果

python
splitter = PodcastSplitter("episode.mp3")
python
splitter = PodcastSplitter("episode.mp3")

Get detailed silence info

获取详细静音信息

silences = splitter.detect_silence()
print("Detected Silences:") for i, (start, end) in enumerate(silences): duration = (end - start) / 1000 start_time = start / 1000 print(f" {i+1}. {start_time:.1f}s - {duration:.1f}s silence")
silences = splitter.detect_silence()
print("检测到的静音:") for i, (start, end) in enumerate(silences): duration = (end - start) / 1000 start_time = start / 1000 print(f" {i+1}. {start_time:.1f}秒 - 静音时长 {duration:.1f}秒")

Print summary

打印摘要

splitter.print_silence_report()
undefined
splitter.print_silence_report()
undefined

Detection Settings Guide

检测设置指南

Audio TypeThresholdMin SilenceNotes
Quiet studio-50 dBFS500msVery sensitive
Normal podcast-40 dBFS1000msDefault
Noisy recording-35 dBFS1500msLess sensitive
Music with breaks-30 dBFS2000msFor spoken breaks
音频类型阈值最小静音时长说明
安静录音室-50 dBFS500毫秒灵敏度高
普通播客-40 dBFS1000毫秒默认设置
噪音录音-35 dBFS1500毫秒灵敏度低
带停顿的音乐-30 dBFS2000毫秒适用于语音停顿场景

Adjusting Sensitivity

调整灵敏度

  • More splits: Lower threshold (e.g., -50), shorter min_silence
  • Fewer splits: Higher threshold (e.g., -30), longer min_silence
  • Natural feel: Longer keep_silence (500-1000ms)
  • Tight edits: Shorter keep_silence (100-200ms)
  • 更多片段:降低阈值(如-50),缩短最小静音时长
  • 更少片段:提高阈值(如-30),延长最小静音时长
  • 自然效果:延长边缘保留静音时长(500-1000毫秒)
  • 紧凑编辑:缩短边缘保留静音时长(100-200毫秒)

Dependencies

依赖项

pydub>=0.25.0
Note: Requires FFmpeg installed on system.
pydub>=0.25.0
注意:需要在系统上安装FFmpeg。

Limitations

局限性

  • Works best with speech content (not music)
  • Very noisy recordings may need threshold adjustment
  • Long files use significant memory
  • No automatic chapter naming (manual rename needed)
  • 对语音内容效果最佳(不适用于音乐)
  • 噪音较大的录音可能需要调整阈值
  • 长文件会占用大量内存
  • 不支持自动章节命名(需要手动重命名)