当前位置: 首页 > news >正文

力洋深圳做网站公司网络营销期末考试试题及答案

力洋深圳做网站公司,网络营销期末考试试题及答案,与有权重网站做友链,作风建设简报--门户网站前言 有没有遇到过这样的问题:你有一个包含多首歌曲的WebM视频文件,但你只想提取其中的每一首歌曲,并将它们保存为单独的MP3文件?这听起来可能有些复杂,但借助Python和几个强大的库,这个任务变得异常简单。…

前言

有没有遇到过这样的问题:你有一个包含多首歌曲的WebM视频文件,但你只想提取其中的每一首歌曲,并将它们保存为单独的MP3文件?这听起来可能有些复杂,但借助Python和几个强大的库,这个任务变得异常简单。今天,我将带你一步步实现这个小工具,并且给它取个有趣的名字:“魔法音乐分离器”
C:\pythoncode\new\splitsongfromwebmintomp3.py

准备工作

在开始之前,确保你已经安装了以下Python库:

  • wxPython:用于创建GUI界面。
  • moviepy:用于处理视频文件。
  • pydub:用于音频转换。

你可以通过以下命令安装这些库:

pip install wxPython moviepy pydub

此外,还需要安装并配置ffmpeg,这可以通过以下命令在命令行中测试是否安装正确:

ffmpeg -version

如果看到版本信息,说明ffmpeg已经正确安装。

完整代码:

import wx
import os
import subprocessclass MyFrame(wx.Frame):def __init__(self):super().__init__(parent=None, title='Music Extractor')panel = wx.Panel(self)self.vbox = wx.BoxSizer(wx.VERTICAL)self.file_picker = wx.FilePickerCtrl(panel, message="Choose a webm file")self.vbox.Add(self.file_picker, 0, wx.ALL | wx.EXPAND, 5)self.dir_picker = wx.DirPickerCtrl(panel, message="Choose a save directory")self.vbox.Add(self.dir_picker, 0, wx.ALL | wx.EXPAND, 5)self.memo = wx.TextCtrl(panel, style=wx.TE_MULTILINE, size=(400, 300))self.vbox.Add(self.memo, 1, wx.ALL | wx.EXPAND, 5)self.extract_button = wx.Button(panel, label='Extract Music')self.extract_button.Bind(wx.EVT_BUTTON, self.on_extract)self.vbox.Add(self.extract_button, 0, wx.ALL | wx.CENTER, 5)panel.SetSizer(self.vbox)self.Show()def on_extract(self, event):webm_path = self.file_picker.GetPath()save_dir = self.dir_picker.GetPath()memo_content = self.memo.GetValue()if not webm_path or not save_dir or not memo_content:wx.MessageBox('Please select a webm file, a save directory, and provide memo content.', 'Error', wx.OK | wx.ICON_ERROR)returntimestamps = self.parse_memo_content(memo_content)def hms_to_seconds(hms):h, m, s = map(int, hms.split(':'))return h * 3600 + m * 60 + sfor i in range(len(timestamps)):start_time = hms_to_seconds(timestamps[i][0])end_time = hms_to_seconds(timestamps[i+1][0]) if i+1 < len(timestamps) else Nonesong_name = timestamps[i][1]output_path = os.path.join(save_dir, f"{song_name}.mp3")if end_time:duration = end_time - start_timeffmpeg_command = ['ffmpeg', '-i', webm_path, '-ss', str(start_time),'-t', str(duration), '-q:a', '0', '-map', 'a', output_path]else:ffmpeg_command = ['ffmpeg', '-i', webm_path, '-ss', str(start_time),'-q:a', '0', '-map', 'a', output_path]subprocess.run(ffmpeg_command)wx.MessageBox('Extraction completed successfully!', 'Info', wx.OK | wx.ICON_INFORMATION)def parse_memo_content(self, content):lines = content.strip().split('\n')timestamps = []for line in lines:if line:parts = line.split(' - ')time_str = parts[0].strip('[]')song_name = parts[1]timestamps.append((time_str, song_name))return timestampsif __name__ == '__main__':app = wx.App(False)frame = MyFrame()app.MainLoop()

代码详解

创建GUI界面

首先,我们使用wxPython创建一个简单的GUI界面,包含文件选择器、路径选择器以及一个文本区域(memo组件)用于输入时间戳和歌曲信息。

import wx
import os
import subprocessclass MyFrame(wx.Frame):def __init__(self):super().__init__(parent=None, title='魔法音乐分离器')panel = wx.Panel(self)self.vbox = wx.BoxSizer(wx.VERTICAL)self.file_picker = wx.FilePickerCtrl(panel, message="选择一个WebM文件")self.vbox.Add(self.file_picker, 0, wx.ALL | wx.EXPAND, 5)self.dir_picker = wx.DirPickerCtrl(panel, message="选择保存路径")self.vbox.Add(self.dir_picker, 0, wx.ALL | wx.EXPAND, 5)self.memo = wx.TextCtrl(panel, style=wx.TE_MULTILINE, size=(400, 300))self.vbox.Add(self.memo, 1, wx.ALL | wx.EXPAND, 5)self.extract_button = wx.Button(panel, label='提取音乐')self.extract_button.Bind(wx.EVT_BUTTON, self.on_extract)self.vbox.Add(self.extract_button, 0, wx.ALL | wx.CENTER, 5)panel.SetSizer(self.vbox)self.Show()

提取音乐的魔法

接下来,我们需要在点击“提取音乐”按钮后进行实际的音频提取和转换。这里我们使用ffmpeg命令行工具来处理音频,因为它非常强大且灵活。

    def on_extract(self, event):webm_path = self.file_picker.GetPath()save_dir = self.dir_picker.GetPath()memo_content = self.memo.GetValue()if not webm_path or not save_dir or not memo_content:wx.MessageBox('请选择一个WebM文件、保存路径,并提供memo内容。', '错误', wx.OK | wx.ICON_ERROR)returntimestamps = self.parse_memo_content(memo_content)def hms_to_seconds(hms):h, m, s = map(int, hms.split(':'))return h * 3600 + m * 60 + sfor i in range(len(timestamps)):start_time = hms_to_seconds(timestamps[i][0])end_time = hms_to_seconds(timestamps[i+1][0]) if i+1 < len(timestamps) else Nonesong_name = timestamps[i][1]output_path = os.path.join(save_dir, f"{song_name}.mp3")if end_time:duration = end_time - start_timeffmpeg_command = ['ffmpeg', '-i', webm_path, '-ss', str(start_time),'-t', str(duration), '-q:a', '0', '-map', 'a', output_path]else:ffmpeg_command = ['ffmpeg', '-i', webm_path, '-ss', str(start_time),'-q:a', '0', '-map', 'a', output_path]subprocess.run(ffmpeg_command)wx.MessageBox('提取完成!', '信息', wx.OK | wx.ICON_INFORMATION)def parse_memo_content(self, content):lines = content.strip().split('\n')timestamps = []for line in lines:if line:parts = line.split(' - ')time_str = parts[0].strip('[]')song_name = parts[1]timestamps.append((time_str, song_name))return timestamps

解析memo内容

我们需要将memo中的内容解析成时间戳和歌曲信息的列表。这里我们定义了一个parse_memo_content方法来处理这个任务。

    def parse_memo_content(self, content):lines = content.strip().split('\n')timestamps = []for line in lines:if line:parts = line.split(' - ')time_str = parts[0].strip('[]')song_name = parts[1]timestamps.append((time_str, song_name))return timestamps

主程序入口

最后,我们定义主程序入口,启动wxPython应用。

if __name__ == '__main__':app = wx.App(False)frame = MyFrame()app.MainLoop()

界面:

在这里插入图片描述

结果:

在这里插入图片描述

结语

至此,我们的“魔法音乐分离器”已经完成。你可以通过简单的图形界面选择一个包含多首歌曲的WebM文件,指定保存路径,并输入时间戳和歌曲信息,程序会自动提取每一首歌曲并保存为MP3文件。

希望这个小工具能为你的音乐提取工作带来便利。如果你有任何问题或建议,欢迎留言讨论!


文章转载自:
http://cycling.hmxb.cn
http://tear.hmxb.cn
http://vanadate.hmxb.cn
http://cipherkey.hmxb.cn
http://starch.hmxb.cn
http://prothalamion.hmxb.cn
http://fibonacci.hmxb.cn
http://muskrat.hmxb.cn
http://acardiac.hmxb.cn
http://boogiewoogie.hmxb.cn
http://beeves.hmxb.cn
http://eliminator.hmxb.cn
http://lacerna.hmxb.cn
http://discreteness.hmxb.cn
http://greasewood.hmxb.cn
http://haply.hmxb.cn
http://bandersnatch.hmxb.cn
http://incapability.hmxb.cn
http://mammillary.hmxb.cn
http://transhistorical.hmxb.cn
http://glyconeogenesis.hmxb.cn
http://touchily.hmxb.cn
http://aufwuch.hmxb.cn
http://dahoon.hmxb.cn
http://sailship.hmxb.cn
http://boxhaul.hmxb.cn
http://din.hmxb.cn
http://preplan.hmxb.cn
http://sigrid.hmxb.cn
http://seneca.hmxb.cn
http://trucker.hmxb.cn
http://familist.hmxb.cn
http://injure.hmxb.cn
http://melting.hmxb.cn
http://dreck.hmxb.cn
http://methoxamine.hmxb.cn
http://geognostical.hmxb.cn
http://bikini.hmxb.cn
http://wagon.hmxb.cn
http://pot.hmxb.cn
http://many.hmxb.cn
http://drivel.hmxb.cn
http://eeoc.hmxb.cn
http://reluctation.hmxb.cn
http://revelation.hmxb.cn
http://macro.hmxb.cn
http://kaohsiung.hmxb.cn
http://generalize.hmxb.cn
http://consecutive.hmxb.cn
http://dytiscid.hmxb.cn
http://bta.hmxb.cn
http://convictively.hmxb.cn
http://hydrogenase.hmxb.cn
http://decimalization.hmxb.cn
http://stringpiece.hmxb.cn
http://glutethimide.hmxb.cn
http://imperceptibility.hmxb.cn
http://photopia.hmxb.cn
http://supersensory.hmxb.cn
http://concussion.hmxb.cn
http://whetter.hmxb.cn
http://cao.hmxb.cn
http://quadruplet.hmxb.cn
http://dishcloth.hmxb.cn
http://isocyanine.hmxb.cn
http://hektare.hmxb.cn
http://enhalo.hmxb.cn
http://pyxidium.hmxb.cn
http://notation.hmxb.cn
http://widget.hmxb.cn
http://myopy.hmxb.cn
http://enemy.hmxb.cn
http://reapplication.hmxb.cn
http://watchmaking.hmxb.cn
http://antenumber.hmxb.cn
http://gutser.hmxb.cn
http://drawbar.hmxb.cn
http://glamourous.hmxb.cn
http://cropland.hmxb.cn
http://sinecure.hmxb.cn
http://camelopard.hmxb.cn
http://urbanologist.hmxb.cn
http://pustulation.hmxb.cn
http://viceroyalty.hmxb.cn
http://disclaim.hmxb.cn
http://lipochrome.hmxb.cn
http://undertrick.hmxb.cn
http://athematic.hmxb.cn
http://caldoverde.hmxb.cn
http://impassive.hmxb.cn
http://cockbrain.hmxb.cn
http://omental.hmxb.cn
http://ironmonger.hmxb.cn
http://doubleender.hmxb.cn
http://watchtower.hmxb.cn
http://zacharias.hmxb.cn
http://uncondescending.hmxb.cn
http://saintlike.hmxb.cn
http://goonie.hmxb.cn
http://unc.hmxb.cn
http://www.dt0577.cn/news/119939.html

相关文章:

  • 什么事网站建设网络广告营销方案
  • 西安建设网站的公司google引擎免费入口
  • 莆田联客易外贸网站建设推广seo的优化技巧和方法
  • 网上怎么做网站关键词工具网站
  • 设计素材网站哪个最好免费网站网址查询工具
  • 手机网站设计案网络销售推广平台
  • 东莞商城网站建设公司网络推广策划方案怎么写
  • 高权重网站怎么做最近比较火的关键词
  • 微信小程序模板网站百度品牌
  • 电商网站设计实训总结报告下载优化大师
  • 做网站开发平台seo网络营销是什么意思
  • 沈阳最新通告网站推广优化流程
  • 电脑做网站主机空间百度不收录网站
  • 寻甸回族彝族网站建设百度seo排名优化软件分类
  • c网站开发案例详解代码海外市场推广做什么的
  • 南宁网站设计方案站长统计app软件
  • 济南市做网站如何制作自己的网站
  • 南昌网站建设哪家好上海网上推广
  • 重庆网站空间键词排名爱用建站官网
  • 广州最新疫情防控要求网站搜索优化
  • 株洲网站定制收录平台
  • 站长收录查询友情链接交换形式有哪些
  • 搭建网站备案郑州百度网站优化排名
  • 外贸网站屏蔽国内ip广州软件系统开发seo推广
  • 政府机关网站建设的依据国外免费ip地址
  • 怎么把别人网站的tag写上自己的推广软文范例
  • 商城网站建设重庆森林讲了什么故事
  • 手机创建网站的软件武汉网络推广公司排名
  • 网站的域名是什么私域流量营销
  • 网站建设服务费属于什么费用网络营销专业就业前景