-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsentences.py
32 lines (22 loc) · 984 Bytes
/
sentences.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#! python3
import argparse
from pydub import *
import pydub
parser = argparse.ArgumentParser(description='Generate an audio sentence from a written one, given a folder full of individual word audio clips (in mp3).')
parser.add_argument('words', metavar='word', type=str, nargs='+', help='The words (or sentences) to be converted')
parser.add_argument('--outfile', default='sentence.mp3', type=str, help='The file to write out the audio to, defaults to "sentence.mp3"', nargs='?')
args = parser.parse_args()
words = args.words
print('Converting "' + (' '.join(words)) + '" to audio')
audio_parts = list()
for word in words:
audio_parts.append(AudioSegment.from_mp3(word+'.mp3'))
result = audio_parts.pop(0)
for part in audio_parts:
result = result + part.strip_silence()
result = result.compress_dynamic_range()
outfile = args.outfile
if ( not outfile.endswith('.mp3') ):
outfile = outfile + '.mp3'
print('Writing out audio to ' + outfile)
result.export(outfile)