Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Tue Apr 16, 2024 3:59 am

Hi Team,

Please let us know how to add audio file (.wav) in the Document. I have attached the sample file for your reference

Thanks in advance

pr20080798
 
Posts: 159
Joined: Wed Jan 20, 2021 1:15 pm

Tue Apr 16, 2024 6:15 am

Hi,

Thanks for your inquiry.
For your requirement, please refer to the following code:
Code: Select all
// Create a Document object to store the content of the document
Document doc = new Document();

// Add a Section to the document
Section sec = doc.addSection();

// Add a Paragraph within the Section
Paragraph paragraph = sec.addParagraph();

// Create a DocPicture object for inserting images
DocPicture picture = new DocPicture(doc);

// Load an image file into the DocPicture object
picture.loadImage("data/audio.jpg");

// Add an OLE object in the Paragraph, which contains an audio file and using an image as an icon
DocOleObject ole = paragraph.appendOleObject("data/test.mp3", picture, OleObjectType.Wave_Sound);

// Set the OLE object not to display as an icon
ole.setDisplayAsIcon(false);

// Save the document as a Docx format file
doc.saveToFile("output/AddOLE.docx", FileFormat.Docx_2013);

// Release the resources of the document
doc.dispose();


Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 997
Joined: Tue Mar 08, 2022 2:02 am

Tue Apr 23, 2024 5:09 am

Thank you for your response .

I added your code but Audio will not play when i click on audio icon ,My audio file extension is .wav .Please help us to solve this issue.

pr20080798
 
Posts: 159
Joined: Wed Jan 20, 2021 1:15 pm

Tue Apr 23, 2024 6:02 am

Hi,

Thanks for your feedback.
When I click on the icon of wav in resulting Word file, a window will be poped-up to let me to open the wav file through software. As shown in the following screenshot.
Is any windows poped-up in your resulting word file? Could you please offer your word file and wav file to help us do further investigation, you could upload it via Dropbox or OneDrive server, then share us with the download link. Thanks in advance.
333.png


Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 997
Joined: Tue Mar 08, 2022 2:02 am

Mon Apr 29, 2024 4:54 am

Hi Abel ,

I sent mail ,Please check it

Thanks

pr20080798
 
Posts: 159
Joined: Wed Jan 20, 2021 1:15 pm

Tue Apr 30, 2024 1:33 am

Hi,

Thanks. We have received your emails and have replied to you. Please check your emails.

Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2771
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.Doc