annotate demo/workspace/radioplay-gen_approach1.py @ 13:16066f0a7127 tip

fixed the problem with brat
author Emmanouil Theofanis Chourdakis <e.t.chourdakis@qmul.ac.uk>
date Sat, 08 Dec 2018 11:02:40 +0000
parents 90155bdd5dd6
children
rev   line source
e@0 1 import numpy as np
e@0 2 import librosa
e@0 3 import argparse
e@0 4 import sys
e@0 5 from approach1 import *
e@0 6 import soundfile as sf
e@0 7 from rtsfx import *
e@0 8
e@0 9 if __name__ == "__main__":
e@0 10 argparser = argparse.ArgumentParser(
e@0 11 description="Converts script .txt files to radioplays downmixes"
e@0 12 )
e@0 13
e@0 14 argparser.add_argument(
e@0 15 'script_path',
e@0 16 type=str,
e@0 17 help="The script .txt path"
e@0 18 )
e@0 19
e@0 20 #
e@0 21 # argparser.add_argument(
e@0 22 # 'annot_path',
e@0 23 # type=str,
e@0 24 # help="The script .ann path"
e@0 25 # )
e@0 26
e@0 27 argparser.add_argument(
e@0 28 'sound_path',
e@0 29 type=str,
e@0 30 help="The music and sfx files path"
e@0 31 )
e@0 32
e@0 33 argparser.add_argument(
e@0 34 'speech_path',
e@0 35 type=str,
e@0 36 help="The speech files path"
e@0 37 )
e@0 38
e@0 39 argparser.add_argument(
e@0 40 'output_path',
e@0 41 type=str,
e@0 42 help="The music and sfx files path"
e@0 43 )
e@0 44
e@0 45 args = argparser.parse_args()
e@0 46 if args.output_path.split('.')[-1] != 'wav':
e@0 47 print("Sorry, only .wav files are supported for output")
e@0 48 sys.exit()
e@0 49
e@0 50 with open(args.script_path) as f:
e@0 51 input_txt = f.read()
e@0 52 #
e@0 53 # with open(args.annot_path) as f:
e@0 54 # input_ann = f.read()
e@0 55
e@0 56 # preprocessor = Preprocessor()
e@0 57 # preprocessed_text = preprocessor.parse_str(input_txt, input_ann)
e@0 58 #
e@0 59 # with open(args.script_path.split('/')[-1].replace('.txt', '_preprocessed.txt'), 'w') as f:
e@0 60 # f.write(preprocessed_text)
e@0 61 #
e@0 62 #
e@0 63 # print(preprocessed_text)
e@0 64
e@0 65 preprocessed_text = input_txt
e@0 66
e@0 67 parser = Parser()
e@0 68 parsed_script = parser.parse_str(preprocessed_text)
e@0 69
e@0 70
e@0 71 with open(args.script_path.split('/')[-1].replace('txt','json'), 'w') as f:
e@0 72 f.write(str(parsed_script))
e@0 73
e@0 74 director = Director(parsed_script, args.sound_path, args.speech_path)
e@0 75 multitrack = director.generate_multitrack()
e@0 76
e@0 77 mixer = Mixer(multitrack)
e@0 78 downmix = mixer.get_downmix()
e@0 79
e@0 80 master = Master(downmix)
e@0 81 mastered = master.get_mastered()
e@0 82
e@0 83 librosa.output.write_wav(args.output_path, mastered, sr=44100, norm=False)
e@0 84 #sf.write(args.output_path, downmix, 44100, format=args.output_path.split('.')[-1])
e@0 85
e@0 86
e@0 87
e@0 88
e@0 89