e@0: import numpy as np e@0: import librosa e@0: import argparse e@0: import sys e@0: from approach1 import * e@0: import soundfile as sf e@0: from rtsfx import * e@0: e@0: if __name__ == "__main__": e@0: argparser = argparse.ArgumentParser( e@0: description="Converts script .txt files to radioplays downmixes" e@0: ) e@0: e@0: argparser.add_argument( e@0: 'script_path', e@0: type=str, e@0: help="The script .txt path" e@0: ) e@0: e@0: # e@0: # argparser.add_argument( e@0: # 'annot_path', e@0: # type=str, e@0: # help="The script .ann path" e@0: # ) e@0: e@0: argparser.add_argument( e@0: 'sound_path', e@0: type=str, e@0: help="The music and sfx files path" e@0: ) e@0: e@0: argparser.add_argument( e@0: 'speech_path', e@0: type=str, e@0: help="The speech files path" e@0: ) e@0: e@0: argparser.add_argument( e@0: 'output_path', e@0: type=str, e@0: help="The music and sfx files path" e@0: ) e@0: e@0: args = argparser.parse_args() e@0: if args.output_path.split('.')[-1] != 'wav': e@0: print("Sorry, only .wav files are supported for output") e@0: sys.exit() e@0: e@0: with open(args.script_path) as f: e@0: input_txt = f.read() e@0: # e@0: # with open(args.annot_path) as f: e@0: # input_ann = f.read() e@0: e@0: # preprocessor = Preprocessor() e@0: # preprocessed_text = preprocessor.parse_str(input_txt, input_ann) e@0: # e@0: # with open(args.script_path.split('/')[-1].replace('.txt', '_preprocessed.txt'), 'w') as f: e@0: # f.write(preprocessed_text) e@0: # e@0: # e@0: # print(preprocessed_text) e@0: e@0: preprocessed_text = input_txt e@0: e@0: parser = Parser() e@0: parsed_script = parser.parse_str(preprocessed_text) e@0: e@0: e@0: with open(args.script_path.split('/')[-1].replace('txt','json'), 'w') as f: e@0: f.write(str(parsed_script)) e@0: e@0: director = Director(parsed_script, args.sound_path, args.speech_path) e@0: multitrack = director.generate_multitrack() e@0: e@0: mixer = Mixer(multitrack) e@0: downmix = mixer.get_downmix() e@0: e@0: master = Master(downmix) e@0: mastered = master.get_mastered() e@0: e@0: librosa.output.write_wav(args.output_path, mastered, sr=44100, norm=False) e@0: #sf.write(args.output_path, downmix, 44100, format=args.output_path.split('.')[-1]) e@0: e@0: e@0: e@0: e@0: