In various cases, audio clips are used to make the PowerPoint presentations more interactive. To add audio in a PPT/PPTX presentation, MS PowerPoint provides an audio frame object. In this article, you will learn how to add an audio frame to a PowerPoint PPT in Python. Moreover, you will come to know how to extract audio from a presentation and save it as a file.
- Python Library to Add Audio in PowerPoint PPT
- Add an Audio in a PowerPoint PPT
- Extract Audio from a PowerPoint PPT
Info: Aspose, through its online MP4 to MP3 converter, now provides an online tool that allows you to extract the audio from a video.
Python Library to Add Audio in PowerPoint
To add and extract audio in PowerPoint presentations, we will use Aspose.Slides for Python via .NET. It is a powerful library that is used to create and manipulate PowerPoint presentations seamlessly. You can install it from PyPI using the following command.
> pip install aspose.slides
Add Audio in PowerPoint PPT in Python
The following are the steps to insert audio into a PowerPoint PPT in Python.
- First, create a new presentation or load an existing one using Presentation class.
- Get reference of a slide from Presentations.slides collection.
- Load the audio from file.
- Add audio frame using Slide.shapes.add_audio_frame_embedded() method.
- Set the additional properties such as play mode and volume.
- Finally, save the presentation using Presentation.save(string, SaveFormat) method.
The following code sample shows how to add audio in a PowerPoint PPT in Python.
Extract Audio from PowerPoint in Python
You can also extract the audios which are embedded into a PPT/PPTX presentation. The following are the steps to perform this operation.
- First, load the PPT/PPTX file using Presentation class.
- Then, loop through slides in Presentation.slides collection.
- For each slide, loop through the collection of shapes it has.
- If shape is a AudioFrame, then extract and save the embedded audio.
The following code sample shows how to extract audio from a PowerPoint PPTX in Python.
Get a Free License
Use Aspose.Slides for Python without evaluation limitations by getting a free temporary license.
Conclusion
In this article, you have learned how to add audio in PowerPoint PPT or PPTX in Python. Moreover, you have seen how to extract the audios from PowerPoint presentations programmatically. Besides, you can read more about Aspose.Slides for Python using the documentation. In addition, you can post your question to our forum.