-
Notifications
You must be signed in to change notification settings - Fork 112
Remove pydub dependency #529
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "trackio": patch | ||
| --- | ||
|
|
||
| feat:Remove pydub dependency | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,11 +1,12 @@ | ||||||||||||||
| import os | ||||||||||||||
| import shutil | ||||||||||||||
| import subprocess | ||||||||||||||
| import warnings | ||||||||||||||
| import wave | ||||||||||||||
| from pathlib import Path | ||||||||||||||
| from typing import Literal | ||||||||||||||
|
|
||||||||||||||
| import numpy as np | ||||||||||||||
| from pydub import AudioSegment | ||||||||||||||
|
|
||||||||||||||
| from trackio.media.media import TrackioMedia | ||||||||||||||
| from trackio.media.utils import check_ffmpeg_installed, check_path | ||||||||||||||
|
|
@@ -156,12 +157,33 @@ def write_audio( | |||||||||||||
| check_ffmpeg_installed() | ||||||||||||||
|
|
||||||||||||||
| channels = 1 if pcm.ndim == 1 else pcm.shape[1] | ||||||||||||||
| audio = AudioSegment( | ||||||||||||||
| pcm.tobytes(), | ||||||||||||||
| frame_rate=sample_rate, | ||||||||||||||
| sample_width=2, # int16 | ||||||||||||||
| channels=channels, | ||||||||||||||
| ) | ||||||||||||||
|
|
||||||||||||||
| file = audio.export(str(filename), format=format) | ||||||||||||||
| file.close() | ||||||||||||||
| pcm_bytes = pcm.tobytes() | ||||||||||||||
|
|
||||||||||||||
| if format == "wav": | ||||||||||||||
| with wave.open(str(filename), "wb") as wf: | ||||||||||||||
| wf.setnchannels(channels) | ||||||||||||||
| wf.setsampwidth(2) | ||||||||||||||
| wf.setframerate(sample_rate) | ||||||||||||||
| wf.writeframes(pcm_bytes) | ||||||||||||||
| else: | ||||||||||||||
| cmd = [ | ||||||||||||||
| "ffmpeg", | ||||||||||||||
| "-y", | ||||||||||||||
| "-loglevel", | ||||||||||||||
| "error", | ||||||||||||||
| "-f", | ||||||||||||||
| "s16le", | ||||||||||||||
| "-ar", | ||||||||||||||
| str(sample_rate), | ||||||||||||||
| "-ac", | ||||||||||||||
| str(channels), | ||||||||||||||
| "-i", | ||||||||||||||
| "pipe:0", | ||||||||||||||
|
||||||||||||||
| "pipe:0", | |
| "pipe:0", | |
| "-f", | |
| format, | |
| "-codec:a", | |
| "libmp3lame", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor formatting: add a space after
feat:so the changeset summary reads cleanly (e.g.,feat: Remove pydub dependency).