Ejemplo n.º 1
0
 def from_text(cls, text, language='en-US', rate=0.4, videopath=None):
     """
     Create a video from a text.
     """
     speaker = GoogleSpeaker()
     audio_filepath = speaker.speak(text, language=language, rate=rate)
     if not videopath:
         basename = os.path.splitext(os.path.basename(audio_filepath))[0]
         filename = f'{basename}{cls.TARGET_EXTENSION}'
         video_path = path_in_medialib(filename)
     analyst = AudioAnalyst(audio_filepath, text)
     analysis = analyst.analyse()
     image_maker = ImageMaker(analysis)
     pattern = image_maker.save_images()
     outdict = {'vcodec': 'h264', 'shortest': None}
     image = ffmpeg.input(pattern)
     audio = ffmpeg.input(audio_filepath)
     try:
         ffmpeg.output(image, audio, video_path,
                       **outdict).run(capture_stdout=True,
                                      capture_stderr=True)
         return videopath
     except ffmpeg.Error as e:
         print('stdout:', e.stdout.decode('utf8'))
         print('stderr:', e.stderr.decode('utf8'))
         raise e
     return None
Ejemplo n.º 2
0
 def from_audio(filename, text=None):
     wav_file = path_in_medialib(filename)
     analyst = AudioAnalyst(wav_file, text)
     analysis = analyst.analyse()
     image_maker = ImageMaker(analysis)
     pattern = image_maker.save_images()
     outdict = {'vcodec': 'h264', 'shortest': None}
     image = ffmpeg.input(pattern)
     audio = ffmpeg.input(wav_file)
     video_path = f"{wav_file}.mp4"
     try:
         ffmpeg.output(image, audio, video_path,
                       **outdict).run(capture_stdout=True,
                                      capture_stderr=True)
     except ffmpeg.Error as e:
         print('stdout:', e.stdout.decode('utf8'))
         print('stderr:', e.stderr.decode('utf8'))
         raise e
    parser.add_argument("-upload_loc", type=str, default="jacob.stanford.edu:/u/apache/htdocs/mkayser/reports/", help="Location to publish HTML doc to")
    parser.add_argument("-url_loc", type=str, default="http://nlp.stanford.edu/mkayser/reports/", help="URL location where report will appear")
    args = parser.parse_args()

    output_file = "report.html"

    workers = {}
    worker_counts = {}

    html_lines = []

    work_times = []
    total_work_time = 0
    nrows = 0

    imgmaker = ImageMaker(args.block_px, args.padding_px)
    bmpmaker = BitmapMaker(args.bitmap_dim, args.bitmap_dim)

    try:
        os.mkdir(args.output_dir)
    except OSError:
        pass

    with open(args.csv) as fin:
        reader = csv.reader(fin)
        header = next(reader)

        image_index = header.index(args.image_field)
        commands_index = header.index(args.commands_field)
        draw_events_index = header.index(args.draw_events_field)
        worker_id_index = header.index(args.worker_id_field)
Ejemplo n.º 4
0
 def test_cairo_save_images(self):
     """
     Test the frame generation to be used by the Video Maker
     """
     generator = ImageMaker(self.analysis)
     generator.cairo_save_images()
Ejemplo n.º 5
0
                        help="Dimensionality of grid")
    parser.add_argument("-csv",
                        type=str,
                        required=True,
                        help="input CSV file with drawing task results")
    parser.add_argument("-field",
                        type=str,
                        default="Answer.WritingTexts",
                        help="Name of CSV field containing draw events")
    parser.add_argument("-output_dir",
                        type=str,
                        default="output/make_images_from_drawing_task_results",
                        help="output directory for images")
    args = parser.parse_args()

    imgmaker = ImageMaker(args.width, args.padding)
    bmpmaker = BitmapMaker(args.width, args.width)
    np.random.seed(0)

    if not os.path.exists(args.output_dir):
        os.makedirs(args.output_dir)

    with open(args.csv) as fin:
        reader = csv.reader(fin)
        header = next(reader)
        colindex = header.index(args.field)
        for i, row in enumerate(reader):
            commands_str = row[colindex]
            bmpmaker.clear()
            event_sequence = AbsoluteEventSequence.from_mturk_string(
                commands_str)
Ejemplo n.º 6
0
 def test_make_images(self):
     generator = ImageMaker(self.analysis)
     images = generator.make_images()
     images[0].write_to_png(path_in_medialib('test_cairo_frame_0.jpg'))
     images[4].write_to_png(path_in_medialib('test_cairo_frame_4.jpg'))
from image import ImageMaker
from bitmap import BitmapMaker
from events import AbsoluteEventSequence, RelativeEventSequence


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("-width", type=int, default=32, help="Width of blocks in pixels")
    parser.add_argument("-padding", type=int, default=2, help="Padding of blocks in pixels")
    parser.add_argument("-dim", type=int, default=5, help="Dimensionality of grid")
    parser.add_argument("-csv", type=str, required=True, help="input CSV file with drawing task results")
    parser.add_argument("-field", type=str, default="Answer.WritingTexts", help="Name of CSV field containing draw events")
    parser.add_argument("-output_dir", type=str, default="output/make_images_from_drawing_task_results", help="output directory for images")
    args = parser.parse_args()

    imgmaker = ImageMaker(args.width, args.padding)
    bmpmaker = BitmapMaker(args.width, args.width)
    np.random.seed(0)

    if not os.path.exists(args.output_dir):
        os.makedirs(args.output_dir)


    with open(args.csv) as fin:
        reader = csv.reader(fin)
        header = next(reader)
        colindex = header.index(args.field)
        for i,row in enumerate(reader):
            commands_str = row[colindex]
            bmpmaker.clear()
            event_sequence = AbsoluteEventSequence.from_mturk_string(commands_str)
                        default="http://nlp.stanford.edu/mkayser/reports/",
                        help="URL location where report will appear")
    args = parser.parse_args()

    output_file = "report.html"

    workers = {}
    worker_counts = {}

    html_lines = []

    work_times = []
    total_work_time = 0
    nrows = 0

    imgmaker = ImageMaker(args.block_px, args.padding_px)
    bmpmaker = BitmapMaker(args.bitmap_dim, args.bitmap_dim)

    try:
        os.mkdir(args.output_dir)
    except OSError:
        pass

    with open(args.csv) as fin:
        reader = csv.reader(fin)
        header = next(reader)

        image_index = header.index(args.image_field)
        commands_index = header.index(args.commands_field)
        draw_events_index = header.index(args.draw_events_field)
        worker_id_index = header.index(args.worker_id_field)
Ejemplo n.º 9
0
                        type=int,
                        default=16,
                        help="Block width in pixels")
    parser.add_argument("-padding_px",
                        type=int,
                        default=1,
                        help="Padding in pixels")
    parser.add_argument("-bitmap_dim",
                        type=int,
                        default=25,
                        help="Width of bitmap in blocks (assumed square)")

    # Output location
    parser.add_argument("-output_dir",
                        type=str,
                        required=True,
                        help="Directory to write output to")

    args = parser.parse_args()

    output_file = "report.html"

    imgmaker = ImageMaker(args.block_px, args.padding_px)
    bmpmaker = BitmapMaker(args.bitmap_dim, args.bitmap_dim)

    make_dir_unless_exists(args.output_dir)

    convert_commands_to_image_sequence(bmpmaker, imgmaker, args.commands,
                                       "{}/img_".format(args.output_dir),
                                       args.mode)
Ejemplo n.º 10
0
    parser.add_argument("-gridpadding", type=int, default=0, help="How many empty blocks to place on outside of bitmap")
    parser.add_argument("-bc", type=int, default=32, help="Block color")
    parser.add_argument("-nbc", type=int, default=255, help="Non block color")
    parser.add_argument("-gc", type=int, default=128, help="Grid color")
    parser.add_argument("-random_seed", type=int, default=0, help="Random seed")
    parser.add_argument("-output_parent_dir", type=str, default="output", help="parent of output directory for images")
    parser.add_argument("-batch_name", type=str, default=None, help="name of this batch")
    parser.add_argument("-url_prefix", type=str, default="http://nlp.stanford.edu/mkayser/images", help="URL prefix for Mturk HIT's")
    parser.add_argument("-html_folder", type=str, default="jacob.stanford.edu:/u/apache/htdocs/mkayser/images", help="Local name for folder containing HIT's")
    parser.add_argument("-upload", action="store_true", default=False, help="Upload images to HTML folder")
    args = parser.parse_args()

    if not args.batch_name:
        args.batch_name = get_unique_directory_name(args.output_parent_dir,"generate_images")

    imgmaker = ImageMaker(args.width, args.padding, [args.nbc,args.bc,args.gc])
    np.random.seed(args.random_seed)

    output_dir = os.path.join(args.output_parent_dir, args.batch_name)

    if not os.path.exists(output_dir):
        os.makedirs(output_dir)

    write_text_to_file(str(args), os.path.join(output_dir,"args"))
    url_file = os.path.join(output_dir,"image_urls.csv")

    print("Output directory: {}".format(output_dir))
    print("Output CSV file: {}".format(url_file))

    bitmaps = set()