播放MP3文件,不使用默认输出(播放)设备在Python [英] Play mp3 file not using default output (playback) device in Python

查看:2773
本文介绍了播放MP3文件,不使用默认输出(播放)设备在Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道,PyAudio有可能什么播放设备到流上,但PyAudio犯规支持mp3文件进行选择。如果下列问题之一,解决了我的脚本将工作:

I know that on PyAudio it is possible to choose on what playback device to stream on but PyAudio doesnt support mp3 files. My script would work if one of the following problem was solved:


  1. 在PyAudio播放MP3文件

  1. Play mp3 file on PyAudio

从MP3转换为WAV没有,没有任何数据丢失,且无需PyDub(与转换的这种方法,我发现,在一个较长的音频,末端缺失)

Convert from mp3 to wav without without any data loss and without PyDub (with this method of converting, I found out that in a longer audio, the ends are missing)

不知何故从MP3文件到不同的播放设备播放声音(该设备不是默认的)

Somehow play sound from a mp3 file to different playback device (the device is not a default one)

我个人要解决的第一个问题。

Personally I want to solve the first problem.

我将不胜感激,如果我能在PyAudio播放MP3文件,而无需任何数据丢失或质量损失。

I would be grateful if I can play mp3 file on PyAudio without any data loss or quality loss.

编辑:我发现,当我打我的MP3文件(这是顺便说一句,从谷歌文本到语音生成的文件)PyMedia的结局也失踪了一些奇怪的原因所以也许转换方法(2点)工作正常,但问题可能是在其他地方。

I found out that when I play my mp3 file (which is btw a file generated from Google Text To Speech) with PyMedia, the endings also gone missing for some strange reason so perhaps the converting method (point 2.) is working correctly but the problem is probably somewhere else.

推荐答案

首先,请查看link你在你的答复中提到是关于 pymedia ,而不是 pydub

First of all, The link you mentioned in your answer is about pymedia and not pydub.

接下来,我从 MP3 使用 pydub <转换多个文件为 WAV / code>没有问题。

Next, I've converted many files from mp3 to wav using pydub without issues.

如果你想给它一个尝试,这里是一个单行code从 MP3 WAV 。您将能够使用您的code的其余部分使用选项-2这样的。

If you want to give it a try, here is an one liner code to covnert from mp3 to wav. You will be able to use rest of your code this way using option-2.

from pydub import AudioSegment
AudioSegment.from_file("audio.mp3", format="mp3").export("audio.wav", format="wav")

这篇关于播放MP3文件,不使用默认输出(播放)设备在Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆