基本完成代码
This commit is contained in:
commit
dbda6edc00
15 files changed
+953
No files matched your search
@@ -0,0 +1,24 @@
|
||||
# import os
|
||||
import pydub
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
class FileHandler:
|
||||
def __init__(self, directory: str):
|
||||
self.dir_path = Path(directory)
|
||||
|
||||
def combine_waves(self, output_file: str):
|
||||
wav_files = sorted(
|
||||
[f for f in self.dir_path.glob("*.wav")], key=lambda f: f.stat().st_mtime
|
||||
)
|
||||
combined = pydub.AudioSegment.empty()
|
||||
for f in wav_files:
|
||||
audio = pydub.AudioSegment.from_wav(str(f))
|
||||
combined += audio
|
||||
combined.export(output_file, format="wav")
|
||||
|
||||
def wavs_to_mp3(self, wav_file: str, output_file: str):
|
||||
mp3_file = pydub.AudioSegment.empty()
|
||||
audio = pydub.AudioSegment.from_wav(wav_file)
|
||||
mp3_file += audio
|
||||
mp3_file.export(output_file, format="mp3")
|
||||
Reference in new issue
Block a user