videodb
VideoDB Documentation
videodb
VideoDB Documentation
Examples and Tutorials

icon picker
Beep curse words in real-time

VideoDB's are perfect for personalizing content to meet users' requirements. If users prefer not to include curse words in their content, VideoDB allows for these words to be either removed or replaced with a sound overlay such as beep sound in real-time ⚡️
This task, typically complex for video editors, can be accomplished with just a few lines of code using VideoDB.
This technique can also serve as a valuable Content Moderation component for any social content platform, ensuring that content meets the preferences and standards of its audience

🔗 Prerequisites

Ensure you have latest VideoDB installed in your environment. If not, simply run !pip install -U videodb in your terminal.
You'll also need a VideoDB API_KEY, which can be obtained from the VideoDB .

🌐 Connect to VideoDB

Connect to VideoDB using your API key. This establishes a session for uploading and manipulating video and audio files:
from videodb import connect
conn = connect(api_key="YOUR_API_KEY")


📺 Source Your Videos

First, identify the original video. For this tutorial, let's take the Joe Rogan clip, where he is trying to trick Siri into speaking curse words 🤣
# Joe rogan video clip
video = conn.upload(url='https://www.youtube.com/watch?v=7MV6tUCUd-c')

#watch the original video
o_stream = video.generate_stream()
play_stream(o_stream)
Load content from console.videodb.io?
Loading external content may reveal information to 3rd parties. Learn more
Allow

📢 Index the video

Find out the curse words with the spoken Index.
# index spoken content in the video
video.index_spoken_words()

🎛️ Create beep Asset

We have a sample beep sound our github repo beep.wav. For those looking to add a more playful or unique touch, replacing the beep with alternative sound effects, such as a quack or any other sound, can make the content more engaging and fun.
# Import Asset and Timeline
from videodb.asset import VideoAsset, AudioAsset
from videodb.timeline import Timeline

beep = conn.upload(file_path="beep.wav")

#create audio asset from beep sound
AudioAsset(asset_id=beep.id)

🥷🏻 Moderation

To ensure appropriate content management, it's necessary to have a method for identifying profanity and applying a predefined overlay to censor it. In this tutorial, we've included a list of curse words. Feel free to customize this list according to your requirements.
urse_words_list = ['shit', 'ass', 'shity' 'fuck', 'motherfucker','damn', 'fucking', 'motherfuker']

⏭️ Create Fresh Timeline

Let's create a fresh timeline object and add the VideoAsset created from the original video inline. Loop through each word, wherever you match the curse words, add audio overlay created from the beep sound for that timestamp. It's that simple!
# Create a new Timeline object
timeline = Timeline(conn)

# Add the main video inline
video_asset = VideoAsset(asset_id=video.id)
timeline.add_inline(video_asset)

for word in transcript:
text = word.get('text')
if text not in ['-']:
if text in curse_words_list:
beep_start_time = float(word.get('start'))
beep_end_time = float(word.get('end'))
beep_duration = beep_end_time - beep_start_time
#add asset overlay of beep duration
print(f"beep the word: {text}, {beep_start_time}:{beep_end_time} ")
timeline.add_overlay(start=beep_start_time, asset=AudioAsset(asset_id=beep.id,start=0, end=beep_duration))

# generate a fresh stream for this timeline
stream_url = timeline.generate_stream()

🌐 Review and Share Your Moderated Video

Finally, watch and share your new stream:
from videodb import play_stream
play_stream(stream_url)
Load content from console.videodb.io?
Loading external content may reveal information to 3rd parties. Learn more
Allow

⚡️ The Real Power of Programmable Streams

If you have videos pre-uploaded and indexed, running this beep pipeline is real-time. So, based on your users' choices or your platform's policy, you can use information from spoken content to automatically moderate.

Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.