In various cases, the presenters include sounds or audio clips in their presentations. MS PowerPoint provides audio frames to insert the sounds into the slides. In this article, you will learn how to automate the manipulation of audio frames in presentations. Particularly, the article will cover how to insert or extract the audio frames in PowerPoint presentations using C#.
- API to Manipulate Audio Frames in PowerPoint
- Insert an Audio Frame in PowerPoint Presentations
- Extract Audio Frames in PowerPoint Presentations
C# API to Insert or Extract Audio Frames in PowerPoint
To add or extract audio frames in PowerPoint presentations, we will use Aspose.Slides for .NET. It is a class library that lets you automate the creation and manipulation of PowerPoint and OpenOffice presentations. You can either install the API via NuGet or download its DLL.
PM> Install-Package Aspose.Slides.NET
Insert an Audio Frame in PowerPoint Presentations using C#
The following are the steps to insert audio into a PowerPoint presentation using C#.
- First, create a new presentation or load an existing one using Presentation class.
- Then, load the audio from file into a FileStream object.
- Insert the audio to the presentation using ISlide.Shapes.AddAudioFrameEmbedded(Single, Single, Single, Single, Stream) 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 C#
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 from Presentation.Slides collection.
- Get reference of slideshow transition into an ISlideShowTransition object.
- Retrieve the sound data into a byte array from ISlideShowTransition.Sound.BinaryData.
- 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 C#.
Get a Free API License
Use Aspose.Slides for .NET without evaluation limitations by getting a free temporary license.
In this article, you have learned how to insert audio in PowerPoint presentations using C#. 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 .NET. In addition, you can post your question to our forum.