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 or extract the audio frames in PowerPoint presentations using Java.
- API to Manipulate Audio Frames in PowerPoint
- Insert an Audio Frame in PowerPoint Presentations
- Extract Audio Frames in PowerPoint Presentations
Info: Using Aspose new MP4 to MP3 converter, you can easily extract the audio or sound from a video clip.
Java API to Insert or Extract Audio Frames in PowerPoint
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 Presentations using Java
The following are the steps to insert audio into a PowerPoint presentation using 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 insert audio in a PowerPoint presentation.
Extract Audio Frames in PowerPoint Presentations using Java
You can also extract the audio frames from an existing PowerPoint presentation. 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 presentation using Java.
Get a Free API License
Use Aspose.Slides for Java without evaluation limitations by getting a free temporary license.
In this article, you have learned how to insert audio in PowerPoint presentations 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.