# !/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time : 2020/12/24 上午11:39
# @Author : SR
# @Email : srcoder@1163.com
# @File : change_music_type_wav_to_mp3.py
# @Software: PyCharm
import pydub
import os
class ChangeMusicTypeWavToMp3:
def __init__(self, wav_path, music_path, mp3_music_name, wav_music_name):
self.wav_path = wav_path
self.music_path = music_path
self.mp3_music_name = mp3_music_name
self.wav_music_name = wav_music_name
def mkdir_directory(self):
if not os.path.exists(self.wav_path):
os.mkdir(self.wav_path)
if not os.path.exists(self.music_path):
os.mkdir(self.music_path)
def change_music_type(self):
pydub.AudioSegment.from_file(os.path.join(self.wav_path, self.wav_music_name), format='wav').export(
os.path.join(self.music_path, self.mp3_music_name),
format='mp3')
if __name__ == '__main__':
wav_path = input('请输入wav保存文件路径')
music_path = input('请输入转换之后mp3保存文件路径')
wav_music_name = input('请输入wav音乐名称')
mp3_music_name = input('请输入转换之后mp3音乐文件名称')
change = ChangeMusicTypeWavToMp3(wav_path, music_path, mp3_music_name, wav_music_name)
change.mkdir_directory()
change.change_music_type()