简体   繁体   English

用 python(烧瓶)播放 mp3 文件的最快方法是什么?

[英]What is the fastest way to play mp3 files with python (flask)?

I've been making the flask blog.And I made the code in python which play the mp3 file.我一直在制作 flask 博客。我在 python 中编写了播放 mp3 文件的代码。

The trouble is that,as the mp3 file is played,the music itself takes very short time but the updating process of the web page takes long time.问题是,在播放mp3文件时,音乐本身耗时很短,而web页面的更新过程却耗时较长。

Below code is what I've written for it.下面的代码是我为它写的。

os.system("mpg123 " + ("sound1.mp3"))

Does someone know the fastest codes for playing a mp3 file?.有人知道播放 mp3 文件的最快代码吗?

You show very little context, but here a potential answer.您显示的上下文很少,但这里有一个潜在的答案。

If this answer doesn't help you might have to add some more details to your question.如果这个答案没有帮助,您可能需要在您的问题中添加更多详细信息。

You create a web service, that will play an mp3 on the server (not in the browser)您创建了一个 web 服务,它将在服务器上播放 mp3(不在浏览器中)

Is this really what you want to do?这真的是你想做的吗?

The call通话

os.system("mpg123 " + ("sound1.mp3"))

is a blocking call, which means, that only after having played the mp3 file the HTTP response will be sent back to the browser.是一个阻塞调用,这意味着只有在播放完 mp3 文件后,HTTP 响应才会被发送回浏览器。 This could need some time especially if the mp3 file contains some leading or trailing silence.这可能需要一些时间,特别是如果 mp3 文件包含一些前导或尾随静音。

Just try calling it in the background like:只需尝试在后台调用它,例如:

os.system("mpg123 " + "sound1.mp3" + " &")

Now the response will be sent back before the mp3 file has finished playing现在响应将在 mp3 文件播放完毕之前发回

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM