Skip to content

Commit 65a3736

Browse files
Youssef| soundExtractor.py| add ppt sound extractor project
1 parent b18233d commit 65a3736

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

PPT-Audio-Extractor/README.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Sound extractor from PPT files
2+
3+
This is a simple python script to extract embedded audio in ppt files
4+
and merge them into one file.
5+
6+
* To run this script, open the terminal and cd to the directory where your ppt file lies.
7+
* Type the command python3 extractSound.py Filename.ppt where Filename is the ppt file that you want to extract its embedded audio.
8+
* Now, you should find a joinedFile.wav file in the same directory.

PPT-Audio-Extractor/extractSound.py

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import sys
2+
import os.path
3+
import zipfile
4+
import shutil
5+
from pydub import AudioSegment
6+
7+
def main():
8+
fileName = sys.argv[1]
9+
if not os.path.isfile(fileName):
10+
print('File does not exist')
11+
return
12+
with zipfile.ZipFile(fileName,"r") as zip_ref:
13+
zip_ref.extractall("targetdir")
14+
audioFileNum = 1
15+
path = "targetdir/ppt/media/audio{}.wav".format(audioFileNum)
16+
if not os.path.isfile(path):
17+
print('No audio files in this ppt')
18+
return
19+
combinedSound = AudioSegment.from_wav(path)
20+
audioFileNum = audioFileNum + 1
21+
while os.path.isfile("targetdir/ppt/media/audio{}.wav".format(audioFileNum)):
22+
combinedSound = combinedSound + \
23+
AudioSegment.from_wav("targetdir/ppt/media/audio{}.wav".format(audioFileNum))
24+
audioFileNum = audioFileNum + 1
25+
combinedSound.export("joinedFile.wav", format="wav")
26+
dir_path = 'targetdir'
27+
try:
28+
shutil.rmtree(dir_path)
29+
except OSError as e:
30+
print("Error: %s : %s" % (dir_path, e.strerror))
31+
if __name__ == '__main__':
32+
main()
33+

0 commit comments

Comments
 (0)