【问题标题】:Play specified subsection of mp3 in Python 3, Windows 7在 Python 3、Windows 7 中播放 mp3 的指定小节
【发布时间】:2012-02-28 02:29:50
【问题描述】:

我有一个长度为五秒的 MP3 文件。我想播放一个指定的小节,比如从第二个 1.4 到第二个 3.2。我正在使用 Python 3,而不是 Python 2,在 Windows 上工作,而不是 Linux。

我意识到 Python 3 没有一个模块可以解决我的问题,但我想也许我可以让像 mpg123 这样的 MP3 播放器作为后端运行并让我的 Python 程序控制它。 mpg123 的远程命令太有限了。还有其他想法吗?有没有可以在命令行使用的windows程序,像这样:

program -start 1.4 -end 2.3 file.mp3

并从子进程调用?

【问题讨论】:

    标签: windows-7 python-3.x mp3


    【解决方案1】:

    如果你安装了 mplayer 二进制文件或者你可以打包 mplayer,那么你可以使用mplayer.py。它也适用于 Windows 和 Linux 上的 Python 2 和 3。初始化 Player 后,您可以使用 time_pos 属性 (float) 进行搜索,并且需要暂停和停止方法。像这样的:

    player = mplayer.Player()
    player.loadfile("musicfile.mp3")
    player.time_pos = start
    while player.time_pos < stop : pass
    player.stop()
    

    缺点是没有 UI 和热键支持,因为 mplayer 在后台运行并且通信是通过套接字进行的。如果您不需要其他任何东西,最好只使用带有 -ss start time 和 -endpos length in seconds 参数的 mplayer 本身,如下所示:

    mplayer "music.mp3" -ss 20 -endpos 2
    

    这将从 00:20 到 00:22 。你不能指定毫秒,但如果你真的只是想从 A 点到 B 点播放一个或多个音乐文件,那么这个(使用批处理或豪华)是一个更好的解决方案,因为它的依赖更少。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-29
      • 1970-01-01
      • 2016-05-08
      • 1970-01-01
      • 2013-11-30
      相关资源
      最近更新 更多