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 add audio frames in PowerPoint PPT in C#. In addition, we will demonstrate how to extract audio frames from PPT slides.
- API to Add Audio Frames in PowerPoint PPT
- Add an Audio Frame in PowerPoint PPT in C#
- Extract Audio Frames in PowerPoint PPTX in C#
C# API to Add Audio Frames in PowerPoint PPT
To add or extract audio frames in PowerPoint PPT/PPTX, 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
Add an Audio Frame in PowerPoint PPT in C#
The following are the steps to add audio into a PowerPoint PPT 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 PPTX in C#.
Extract Audio Frames in PowerPoint PPT in C#
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 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 PPTX in C#.
C# PowerPoint API - Get a Free 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 PPT 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.
- Convert PowerPoint PPTX/PPT to PNG Images in C#
- Set Slide Background in PowerPoint Presentations using C#
- Generate Thumbnails for PowerPoint PPTX or PPT using C#
- Apply Animation to Text in PowerPoint using C#
- Split PowerPoint Presentations using C#
Tip: If you ever need to extract the audio from a video clip, you can use Aspose MP4 to MP3 converter to do the job.