view 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
line wrap: on
line source
import numpy as np
import librosa
import argparse
import sys
from approach1 import *
import soundfile as sf
from rtsfx import *

if __name__ == "__main__":
    argparser = argparse.ArgumentParser(
        description="Converts script .txt files to radioplays downmixes"
    )

    argparser.add_argument(
        'script_path',
        type=str,
        help="The script .txt path"
    )

    #
    # argparser.add_argument(
    #     'annot_path',
    #     type=str,
    #     help="The script .ann path"
    # )

    argparser.add_argument(
        'sound_path',
        type=str,
        help="The music and sfx files path"
    )

    argparser.add_argument(
        'speech_path',
        type=str,
        help="The speech files path"
    )

    argparser.add_argument(
        'output_path',
        type=str,
        help="The music and sfx files path"
    )

    args = argparser.parse_args()
    if args.output_path.split('.')[-1] != 'wav':
        print("Sorry, only .wav files are supported for output")
        sys.exit()

    with open(args.script_path) as f:
        input_txt = f.read()
    #
    # with open(args.annot_path) as f:
    #     input_ann = f.read()

    # preprocessor = Preprocessor()
    # preprocessed_text = preprocessor.parse_str(input_txt, input_ann)
    #
    # with open(args.script_path.split('/')[-1].replace('.txt', '_preprocessed.txt'), 'w') as f:
    #     f.write(preprocessed_text)
    #
    #
    # print(preprocessed_text)

    preprocessed_text = input_txt

    parser = Parser()
    parsed_script = parser.parse_str(preprocessed_text)


    with open(args.script_path.split('/')[-1].replace('txt','json'), 'w') as f:
        f.write(str(parsed_script))

    director = Director(parsed_script, args.sound_path, args.speech_path)
    multitrack = director.generate_multitrack()

    mixer = Mixer(multitrack)
    downmix = mixer.get_downmix()

    master = Master(downmix)
    mastered = master.get_mastered()

    librosa.output.write_wav(args.output_path, mastered, sr=44100, norm=False)
    #sf.write(args.output_path, downmix, 44100, format=args.output_path.split('.')[-1])