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)
It's always a good practice to make sure you have enough credits before proceeding
acc.available_credits
We will start by importing our csv.
df = pd.read_csv('100-contacts.csv', encoding = "ISO-8859-1")
df.head()
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()
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')
Great! Now to create our synthetic videos we need two things
- Video of a person talking
- 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()
!ls video_actors/
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]
lang = "english_us"
speaker = acc._available_speakers(lang)[1]
text = get_text('James', 'Content strategist', 'Marketing', 'Benton')
audio = acc.text2speech(text, lang, speaker)
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
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]
You can download these videos using acc.download_all_videos()
or acc.download_video(video_id)