Play mp3 file not using default output (playback)

2019-09-02 04:19发布

问题:

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. Play mp3 file on PyAudio

  2. 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)

  3. 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.

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

EDIT: 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.

回答1:

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

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

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")