Sample tutorial for how dword can be used to create customized sales videos
from dword.core import *
from dword.utils import *
import pandas as pd
from pathlib import Path
import os

from datetime import date
import calendar
import time

Let's start by logging into our DeepWord accounts

acc = DeepWord(API_KEY, SECRET_KEY)
login successful

It's always a good practice to make sure you have enough credits before proceeding

acc.available_credits
9983

We will start by importing our csv.

df = pd.read_csv('100-contacts.csv', encoding = "ISO-8859-1")
df.head()
first_name last_name company_name industry Job Title address city county state zip phone1 phone email
0 James Butt Benton Marketing Content strategist 6649 N Blue Gum St New Orleans Orleans LA 70116 504-621-8927 504-845-1427 jbutt@gmail.com
1 Josephine Darakjy Chanay Sales Compensation analyst 4 B Blue Ridge Blvd Brighton Livingston MI 48116 810-292-9388 810-374-9840 josephine_darakjy@darakjy.org
2 Art Venere Chemel Sales Investment advisor 8 W Cerritos Ave #54 Bridgeport Gloucester NJ 8014 856-636-8749 856-264-4130 art@venere.org
3 Lenna Paprocki Feltz Printing Service Marketing Marketing technologist 639 Main St Anchorage Anchorage AK 99501 907-385-4412 907-921-2010 lpaprocki@hotmail.com
4 Donette Foller Printing Dimensions Medical Full stack developer 34 Center St Hamilton Butler OH 45011 513-570-1893 513-549-4561 donette.foller@cox.net

We want to use the columns of this csv to create custom messages for users. Let's write some functions for the same. The first function we will write is to get the current day. For this we will use the date and calendar libraries

def get_day():
    my_date = date.today().weekday()
    return calendar.day_name[my_date]
get_day()
'Tuesday'

Next we'll write a function to greet the users. For this we'll use 4 columns from the csv

def get_text(first_name, job_title, industry, company_name):
    return (f"Hello {first_name}, hope your {get_day()} morning is going well."
            f" We know that {job_title}'s like you in the {industry} industry are always looking"
            f" to better connect with your customers and employees. My name is Carl from Deep Word"
            f" and we enable companies like {company_name} to generate individual personalized videos"
            f" for their customers and employees, at scale, with any piece of data you have on these"
            f" individuals. Let me quickly show you how you can create videos, just like this one"
            f" using Deep Word."
           )
get_text('James', 'Content strategist', 'Marketing', 'Benton')
"Hello James, hope your Tuesday morning is going well. We know that Content strategist's like you in the Marketing industry are always looking to better connect with your customers and employees. My name is Carl from Deep Word and we enable companies like Benton to generate individual personalized videos for their customers and employees, at scale, with any piece of data you have on these individuals. Let me quickly show you how you can create videos, just like this one using Deep Word."

Great! Now to create our synthetic videos we need two things

  1. Video of a person talking
  2. Audio we want them to say

For the video, we will use one of DeepWord's video actors. To download them use:

acc.download_video_actors()
'Successfully downloaded all video actors'
!ls video_actors/
Anna.mp4    Dalton.mp4  Isaac.mp4   Karen.mp4   Mia.mp4     Richard.mp4
Berto.mp4   Emily.mp4   James.mp4   Marcus.mp4  Micheal.mp4 Sam.mp4
Carlos.mp4  Henry.mp4   Julia.mp4   Mary.mp4    Noelle.mp4  Trey.mp4
display_video('video_actors/Berto.mp4')

For the audio, we will iterate over the csv, use that row to generate custom text for each user and then use that custom text to generate an audio using text2speech. Here's what that looks like

acc._available_languages[:10]
['arabic_egypt',
 'arabic_saudi_arabia',
 'bulgarian',
 'catalan',
 'czech',
 'welsh',
 'danish',
 'german_austria',
 'german_switzerland',
 'german_germany']
lang = "english_us"
speaker = acc._available_speakers(lang)[1]
text = get_text('James', 'Content strategist', 'Marketing', 'Benton')
audio = acc.text2speech(text, lang, speaker)
Successfully generated audio file text2speech.mp3
play_audio(audio)

Sounds great!! Doesn't it? We can now put it all together

video = 'video_actors/Berto.mp4'

# audio input
lang = "english_us"
speaker = acc._available_speakers(lang)[1]

# iterate over the data frame
for idx, row in df.iterrows():
    
    # generate custom text for each user
    text = get_text(row['first_name'], row['Job Title'], row['industry'], row['company_name'])
    
    # generate custom audio for each user
    audio = acc.text2speech(text, lang, speaker, outfile = f'{idx}_audio.mp3')
    
    acc.generate_video("video_actors/Berto.mp4", audio, title = f"video_{idx}")
    
    if idx == 2: break
Successfully generated audio file 0_audio.mp3
Successfully generated audio file 1_audio.mp3
Successfully generated audio file 2_audio.mp3

Once you have submitted your videos, it will take 10-15 mins per video to generate the output. You can check the status of each video by using list_videos(). Let's check the metadata for the last video

all_videos = acc.list_videos()
all_videos[0]
{'email': 'test_dword_api@yopmail.com',
 'thumbnail': 'video_b47y6a4xnhkuey3hfb.mp4',
 'title': 'video_2',
 'video_url': 'https://videos-deep-word123.s3.us-east-2.amazonaws.com/output_data/b47y6a4xnhkuey3hfb.mp4',
 'video_duration': '24.96',
 'video_id': 'b47y6a4xnhkuey3hfb',
 'generate_date': '2021-10-06T03:22:30.000Z',
 'output_status': 'Queued'}

You can download these videos using acc.download_all_videos() or acc.download_video(video_id)