In various cases, the presenters use sounds or audio clips in their presentations. To include sounds in the presentations, MS PowerPoint provides audio frames. In this article, you are going to learn how to automate the manipulation of the audio frames. Particularly, the article will cover how to insert audio frames in PowerPoint PPT using Java. In addition, you will learn how to extract audio from PowerPoint PPT/PPTX programmatically.
- API to Add Audio Frames in PowerPoint PPT
- Insert an Audio Frame in PowerPoint PPT in Java
- Extract Audio Frames in PowerPoint PPTX
Java API to Insert Audio Frames in PowerPoint PPT
To add or extract audio frames in presentations, we will use Aspose.Slides for Java. It is a feature-rich API that allows you to create and process PowerPoint and OpenOffice documents. Moreover, it lets you convert the presentations to other file formats. You can either install the API via Maven or download its JAR.
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>http://repository.aspose.com/repo/</url>
</repository>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-slides</artifactId>
<version>21.9</version>
<classifier>jdk16</classifier>
</dependency>
Insert an Audio Frame in PowerPoint PPT using Java
The following are the steps to insert audio into a PowerPoint PPT in Java.
- First, create a new presentation or load an existing one using Presentation class.
- Then, load the audio from file into a FileInputStream object.
- Insert the audio to the presentation using ISlide.getShapes().addAudioFrameEmbedded(float, float, float, float, InputStream) method and get the reference of the returned audio frame into an IAudioFrame object.
- Set the additional properties such as PlayMode, Volume, etc.
- Finally, save the presentation using Presentation.save(String, SaveFormat) method.
The following code sample shows how to embed audio in a PowerPoint PPT in Java.
Extract Audio Frames in PowerPoint PPTX using Java
You can also extract the audio frames from an existing PowerPoint PPT. The following are the steps to perform this operation.
- First, load the PowerPoint presentation using Presentation class.
- Then, get the desired slide into an ISlide object using Presentation.getSlides().get_Item(int index).
- Get reference of slideshow transition into an ISlideShowTransition object.
- Retrieve the sound data into a byte[] array using ISlideShowTransition.getSound().getBinaryData() method.
- Finally, use the byte array or save it as a file.
The following code sample shows how to extract audio from a PowerPoint PPTX in Java.
Java PowerPoint API to Embed Audio - Get a Free License
Use Aspose.Slides for Java without evaluation limitations by getting a free temporary license.
Conclusion
In this article, you have learned how to insert audio in PowerPoint PPT using Java. Moreover, you have seen how to extract the audio clips from presentations programmatically. Besides, you can explore the documentation to learn more about Aspose.Slides for Java. In addition, you can post your question to our forum.
See Also
- Add Watermark to PowerPoint Slides using Java
- Extract Text from PowerPoint Files using Java
- Add, Connect, Remove, or Clone PowerPoint Shapes in Java
- Convert PowerPoint PPTX/PPT to PNG Images in Java
- Generate Thumbnails for PowerPoint PPTX or PPT using Java
Info: Using Aspose new MP4 to MP3 converter, you can easily extract the audio or sound from a video clip.