วิธีเพิ่มเสียงในงานนำเสนอโดยใช้ Python

ในบทความง่ายๆ นี้ เราจะมุ่งเน้นไปที่วิธี เพิ่มเสียงใน Presentation โดยใช้ Python โดยการกำหนดค่าสภาพแวดล้อมโดยใช้ขั้นตอนที่กำหนดไว้อย่างดี และเรียกใช้โค้ดตัวอย่าง แอปพลิเคชันนี้สามารถใช้ในสภาพแวดล้อมที่กำหนดค่าด้วย Python และ .NET Core ในระบบปฏิบัติการ เช่น Windows, macOS หรือ Linux เพื่อ ฝังเสียงใน PPTX โดยใช้ Python

ขั้นตอนในการแทรกเสียงในงานนำเสนอโดยใช้ Python

  1. สร้างสภาพแวดล้อมเพื่อใช้ Aspose.Slides สำหรับ Python ผ่าน .NET ในแอปพลิเคชันของคุณเพื่อเพิ่มเฟรมเสียง
  2. ใช้วัตถุคลาส Presentation เพื่อสร้างงานนำเสนอเปล่าเพื่อฝังกรอบเสียงภายในงานนำเสนอ
  3. โหลดสไลด์ที่เลือกจากคอลเลกชันสไลด์นำเสนอเพื่อเพิ่มกรอบเสียง
  4. เข้าถึงไฟล์เสียงจากดิสก์และใส่กรอบเสียงบนสไลด์โดยใช้เสียงนั้น
  5. โหลดรูปภาพจากดิสก์และตั้งค่าให้เป็นเฟรมเสียงที่มองเห็นได้บนสไลด์
  6. บันทึกงานนำเสนอที่มีเฟรมเสียงฝังอยู่ในดิสก์

ทำตามขั้นตอนข้างต้นใน Python การแทรกเสียงในงานนำเสนอ PowerPoint ทำได้อย่างง่ายดาย โดยกระบวนการจะเริ่มต้นด้วยการสร้างงานนำเสนอเปล่าโดยใช้อินสแตนซ์ของคลาส Presentation และเข้าถึงสไลด์ที่ต้องการภายในคอลเลกชันสไลด์ เราจะเข้าถึงไฟล์เสียงจากดิสก์เพื่อเพิ่มเฟรมเสียงให้กับสไลด์ที่เลือก สุดท้าย รูปภาพจากดิสก์จะถูกโหลดและตั้งค่าเป็นภาพที่แสดงสำหรับเฟรมเสียงก่อนที่จะบันทึกงานนำเสนอที่มีไฟล์เสียงฝังอยู่ในดิสก์

รหัสเพื่อแทรกเสียงในงานนำเสนอโดยใช้ Python

#import aspose.pydrawing as drawing
import aspose.slides as slides
filepath = "C://Words//"
# Applying the licence to embed an audio frame inside the presentation
audioInSlidesLicense = slides.License()
audioInSlidesLicense.set_license(filepath + "Conholdate.Total.Product.Family.lic")
# Create an empty presentation to insert an audio frame
with slides.Presentation() as sampleAudioPres:
#Load the desired slide to add an audio frame
slidePres = sampleAudioPres.slides[0]
#Load the audio file and add that inside the presentation
audiofile = open(filepath + "sample.mp3", 'rb').read()
audio = sampleAudioPres.audios.add_audio(audiofile)
# Insert the Audio Frame inside the slide
audioFrm = slidePres.shapes.add_audio_frame_embedded(50, 150, 300, 350, audio)
# Set the options of play mode and volume of the audio frame
audioFrm.play_mode = slides.VideoPlayModePreset.AUTO
audioFrm.volume = slides.AudioVolumeMode.LOUD
#Insert the audio frame image inside the images collection of the presentation
with open(filepath + "multiple_codes.png", "rb") as bin_image_file:
#Read the entire image file from the disk at once
frameImageData = bin_image_file.read()
imageForFrame = sampleAudioPres.images.add_image(frameImageData)
#Set the image for the audio frame
audioFrm.picture_format.picture.image = imageForFrame
# Save the presentations with audio frame on the disk
sampleAudioPres.save(filepath + "PresentationWithAudio.pptx", slides.export.SaveFormat.PPTX)
print("Audio addition completed")

ด้วยความช่วยเหลือของรหัสที่ค่อนข้างง่ายใน Python การบันทึกเสียง MP3 ในงานนำเสนอ PPT นั้นทำได้อย่างง่ายดายโดยใช้อินเทอร์เฟซ API ที่ง่ายมาก คลาส IAudioFrame ใช้เพื่อแทรกเสียง ซึ่งยังมีตัวตั้งค่าสำหรับคุณสมบัติต่างๆ เช่น เล่นเสียงในลูป โหมดย้อนกลับ โหมดเล่น และซ่อนเสียง เป็นต้น

ในหัวข้อสั้นๆ นี้ เราได้มุ่งเน้นไปที่วิธี แทรกเสียงในการนำเสนอโดยใช้ Python หากคุณสนใจที่จะเรียนรู้เกี่ยวกับการฝังไฟล์วิดีโอในงานนำเสนอ โปรดดูบทความใน วิธีเพิ่มวิดีโอในงานนำเสนอโดยใช้ Python

 ไทย