从PPT中提取声音文件



我正在尝试使用Python从powerpoint中提取声音文件。这是我写的:

from pptx import Presentation
from pptx.enum.shapes import MSO_SHAPE_TYPE
file = open(filepath , 'rb') 
prs = Presentation(file)
for slide in prs.slides:
for shape in slide.shapes:
if shape.shape_type == MSO_SHAPE_TYPE.MEDIA:
print('Found one')

但是,即使每张幻灯片上都有一个mp3文件,它也找不到任何东西,所以对于我打印的每个形状对象,shape_type都是shape.type,奇怪的是,没有GraphicFrame对象,只有图片、文本和自动形状。

如何查找和提取它们?

您可以尝试使用Aspose。Python幻灯片。这个库允许从音频帧中提取声音文件,如下所示:

import aspose.slides as slides
from aspose.slides import AudioFrame
with slides.Presentation("example.pptx") as presentation:
for slide in presentation.slides:
for shape in slide.shapes:
if isinstance(shape, AudioFrame):
audio_data = shape.embedded_audio.binary_data
content_type = shape.embedded_audio.content_type # returns "audio/mpeg", for example
# ...

或者,你可以从这样的演示中获取所有声音文件:

import aspose.slides as slides
from aspose.slides import AudioFrame
with slides.Presentation("example.pptx") as presentation:
for audio in presentation.audios:
audio_data = audio.binary_data
content_type = audio.content_type
# ...

我在Aspose担任支持开发人员。

最新更新