This article demonstrates how to insert an audio file (.wav) in a presentation slide by using Spire.Presentation for Java.
import com.spire.presentation.*; import com.spire.presentation.drawing.FillFormatType; import java.awt.*; import java.awt.geom.Rectangle2D; public class InsertAudio { public static void main(String[] args) throws Exception { //create a Presentation object and load an example PowerPoint file Presentation presentation = new Presentation(); presentation.loadFromFile("C:/Users/Administrator/Desktop/example.pptx"); //add a shape to the first slide Rectangle2D.Double labelRect= new Rectangle2D.Double(50, 120, 100, 50); IAutoShape labelShape = presentation.getSlides().get(0).getShapes().appendShape(ShapeType.RECTANGLE, labelRect); labelShape.getLine().setFillType(FillFormatType.NONE); labelShape.getFill().setFillType(FillFormatType.NONE); labelShape.getTextFrame().setText("Audio:"); labelShape.getTextFrame().getTextRange().setFontHeight(28); labelShape.getTextFrame().getTextRange().setLatinFont(new TextFont("Myriad Pro Light")); labelShape.getTextFrame().getTextRange().getFill().setFillType(FillFormatType.SOLID); labelShape.getTextFrame().getTextRange().getFill().getSolidColor().setColor(Color.BLACK); //append an audio file to the slide Rectangle2D.Double audioRect = new Rectangle2D.Double(170, 120, 50, 50); presentation.getSlides().get(0).getShapes().appendAudioMedia((new java.io.File("C:/Users/Administrator/Desktop/Music.wav")).getAbsolutePath(), audioRect); //save to file presentation.saveToFile("output/InsertAudio.pptx", FileFormat.PPTX_2010); presentation.dispose(); } }