我到处找,我找不到正确播放Ogg文件的方法,它们都在播放wav!
我的问题是:有人知道如何在python中播放Ogg文件吗?
如果有人知道我会非常感激:(
(我在窗口上(
使用pygame您可以在此处了解pygame:了解pygam这里有一个例子:
import pygame #pip install pygame
pygame.mixer.music.init()# initializing the module
pygame.mixer.music.load('your_ogg_file.ogg')# loading the ogg file
pygame.mixer.music.play()# this will simply play the loaded file.
最简单的方法可能是启动媒体播放器应用程序,使用subprocess.Popen
播放文件。
如果您已经安装了与Ogg文件相关联的媒体播放器,那么使用start
命令应该可以工作。
您可以将Pyglet与ffmpeg:一起使用
https://pyglet.readthedocs.io/en/latest/programming_guide/media.html
我不知道这是否对您的情况有用,但这就是我在python 中播放ogg文件所做的
from audioplayer import AudioPlayer
import os
from pydub import AudioSegment
audio_location="location of .ogg file that you want to play" # location of the ogg file that you want to play
audio = AudioSegment.from_file(audio_location, format="ogg")
audio.export("outaudio.mp3", format="mp3") #converts the ogg tile to a temporary mp3 file for playing
AudioPlayer("outaudio.mp3").play(block=True) # plays the converted file
os.remove("outaudio.mp3") # deletets the converted file leaving only the original .ogg file