I have created Ai voice

 From 3 months since now I have found the loopholes of Ai voiceover websites and automated them using my Python HID automation skills. Here are some code I think I have done with my best: 

These automates the process of video and voice creation with Ai.

def getPos(picName, pressAnything = ""):    
    from time import sleep
    from pyautogui import locateCenterOnScreen, press, scroll
    position = ''
    picNameFinal = ''
    if type(picName) == list:
        picNameFinal = picName[0]
    else:
        picNameFinal = picName
    while True:
             
        try:
            position = locateCenterOnScreen(picNameFinal + ".png")
           
            break
        except:
            if type(picName) == list:
                print("Tried name: " + picNameFinal + ".png   Attempt:" + str(picName.index(picNameFinal)))    
                 
                if len(picName)-1 > picName.index(picNameFinal):
                    picNameFinal = picName[picName.index(picNameFinal)+1]
                else:
                    picNameFinal = picName[0]
                    print("No match found for "+picNameFinal+", scanning again...")
                    if pressAnything != "":
                        if pressAnything == "scrollUp":
                            scroll(150)
                        elif pressAnything == "scrollDown":
                            scroll(-150)
                        else:
                            press(pressAnything)
            else:
                if pressAnything != "":
                    if pressAnything == "scrollUp":
                            scroll(150)
                    elif pressAnything == "scrollDown":
                        scroll(-150)
                    else:
                        press(pressAnything)
                print(picName+" not found, trying again")
            sleep(1)
    return position



def NewIncognitoWindow():
    #in order to get to new Incognito window button, first the chrome icon needs to be clicked
    from pyautogui import hotkey
    hotkey("ctrl", "shift", "n")
def getFocusOnChromeUrlBox():
    #this is the box that appears when a chrome window is opened
    from pyautogui import hotkey
    hotkey("ctrl"+"L")
def miniBreak():
    from time import sleep
    sleep(1)
def shortBreak():
    from time import sleep
    sleep(2)
def mediumBreak():
    from time import sleep
    sleep(5)
def longBreak():
    from time import sleep
    sleep(10)
def customBreak(count):
    from time import sleep
    sleep(count)
def paste(text):
    from pyperclip import copy
    from pyautogui import hotkey
    copy(text)
    from time import sleep
    sleep(0.5)
    hotkey("ctrl", "v")
def openNewTab():
    from pyautogui import hotkey
    hotkey("ctrl", "t")
def getAndSaveEmail():
    from pyperclip import paste
    open("emailListForAccounts.txt", 'a').write("\n"+paste())
    return paste()
def goBackToTempMailTab():
    from pyautogui import hotkey
    hotkey("ctrl", "shift", "tab")
def goDown(num):
    from pyautogui import press
    from time import sleep
    for i in range(0,num):
        sleep(0.5)
        press("down")
def getText():
    from pyautogui import hotkey
    from pyperclip import paste
    from time import sleep
    sleep(0.5)
    hotkey("ctrl", "c")
    sleep(0.5)
    return paste()

def getNumberFromRawText(text, serial = 0):
    from re import findall
    numbers = findall(r'\d+', text)
    return numbers[serial]

def goToInvideoTab():
    from pyautogui import hotkey
    from time import sleep
    sleep(0.2)
    hotkey("ctrl", "tab")

def pressEnter():
    from pyautogui import press
    press("enter")

def videoPrepareBreak():
    from time import sleep
    sleep(100)

def finalCreationBreak():
    from time import sleep
    sleep(120)

def exportPreparebreak():
    from time import sleep
    sleep(120)

def finalExportBreak():
    from time import sleep
    sleep(120)

def gatherVideoFromDownloads(vdoName = "input_video.mp4", download_folder_path = "C:\\Users\\Lenovo\\Downloads"):
    from os import listdir, path
    from pathlib import Path
    from tqdm import tqdm

    def get_latest_file(folder_path):
        files = listdir(folder_path)
        full_paths = [path.join(folder_path, file) for file in files]
        latest_file = max(full_paths, key=path.getctime)
        return latest_file

    def copy_and_paste_with_progress(file_path, destination_folder, new_name):
        total_size = path.getsize(file_path)
        chunk_size = 1024*1024  # Adjust the chunk size as needed
        with open(file_path, 'rb') as src, tqdm(total=total_size, unit='B', unit_scale=True, desc='Copying') as pbar:
            with open(path.join(destination_folder, new_name), 'wb') as dest:
                while True:
                    chunk = src.read(chunk_size)
                    if not chunk:
                        break
                    dest.write(chunk)
                    pbar.update(len(chunk))
        # Replace 'your_folder_path' with the path to the folder containing the files
    folder_path = download_folder_path
   
    # Replace 'your_new_file_name' with the desired name for the copied file
    new_file_name = vdoName

    latest_file = get_latest_file(folder_path)

    # Get the path of the directory where the Python script is located
    script_directory = Path(__file__).resolve().parent

    # Copy and paste the latest file to the script directory with the specified name and show progress
    copy_and_paste_with_progress(latest_file, script_directory, new_file_name)

    print(f"Latest file '{latest_file}' copied and pasted as '{new_file_name}' in '{script_directory}'.")

   
def get_latest_file(folder_path = "C:\\Users\\Lenovo\\Downloads"):
    from os import path, listdir
    files = listdir(folder_path)
    full_paths = [path.join(folder_path, file) for file in files]
    latest_file = max(full_paths, key=path.getctime)
    return latest_file



def crop_video(input_path, output_path):
    from moviepy.video.io.VideoFileClip import VideoFileClip
    from moviepy.video.fx.all import crop
    # Load the video clip
    video_clip = VideoFileClip(input_path)

    # Calculate crop dimensions
    crop_height = int(video_clip.size[1] * 0.76)
    crop_width = int(video_clip.size[0] * 0.76)

    # Calculate crop position
    x_position = int((video_clip.size[0] - crop_width)/2)
    y_position = 0

    # Crop the video
    cropped_clip = crop(video_clip, x1=x_position, y1=y_position, x2=x_position + crop_width, y2=y_position + crop_height)

    # Write the cropped video to the output file
    cropped_clip.write_videofile(output_path, codec="libx264", audio_codec="aac")


def cut_off_last_seconds(input_file, output_file, seconds_to_cut=5):
    from moviepy.video.io.VideoFileClip import VideoFileClip
    video_clip = VideoFileClip(input_file)

    # Calculate the duration to keep (total duration - seconds_to_cut)
    new_duration = video_clip.duration - seconds_to_cut

    # Cut the video to the new duration
    new_video_clip = video_clip.subclip(0, new_duration)

    # Write the new video to a file
    new_video_clip.write_videofile(output_file, codec="libx264", audio_codec="aac")

    # Close the video clips to release resources
    video_clip.close()
    new_video_clip.close()


def openChatGPT():
    from pyautogui import click, hotkey
    from autodetectionAi import getPos
    click(getPos(["chromeIconSrs", "chromIconSrsWhileOpened"]))
    miniBreak()
    hotkey('ctrl', 'l')
    miniBreak()
    paste("https://chat.openai.com/")
    miniBreak()
    pressEnter()

def getCopiedText():
    from pyperclip import paste
    return paste()

def closeCurrentWindow():
    from pyautogui import hotkey
    hotkey("alt", "f4")

def startRecording():
    open("booleanFile.txt", 'w').write("true")
   

def stopRecording():
    open("booleanFile2.txt", 'w').write("true")

def replaceSoundFromVideo(input_video, input_wav):
    from moviepy.editor import VideoFileClip
    from moviepy.audio.io.AudioFileClip import AudioFileClip
    # Load the video clip
    video_clip = VideoFileClip(input_video)

    # Mute the audio of the video clip
    muted_clip = video_clip.set_audio(None)

    # Load the audio clip from the provided wav file
    audio_clip = AudioFileClip(input_wav)

    # Cut the audio to match the duration of the video
    video_clip2 = muted_clip.subclip(0, audio_clip.duration)

    # Concatenate the muted video clip with the audio clip
    final_clip = video_clip2.set_audio(audio_clip)
   

    # Write the final video with added audio
    output_file = "final_video_with_audio.mp4"
    final_clip.write_videofile(output_file, codec="libx264", audio_codec="aac")


from autodetectionAi import *
from waysToReach import *
from time import sleep
from pyautogui import click, press


openChatGPT()
longBreak()
miniBreak()
idea = "What are the uses of drones in Hospitals"
paste("Think that you are a youtube video voice-over script writer, now write 5 minutes youtube video script professionaly on "+ idea +". Use simple words to reach wider audience and don't use things like 'Welcome', talk straight to the point.. Get every possible detail and knowledgeable data from online. Be intelligent. You should not write scene types like [This scene should be this] and don't write in dialogue style. A raw fresh voiceover pargraph. Don't use words like 'Narrator:', 'Scene:' Just write only the texts to be talked. Don't be a poet, talk simple. Never use extra text like scenery or closing or opening shot type text. Just write the raw voice-over like a paragraph.")
shortBreak()
pressEnter()
click(getPos(["copyButtonCGPT", "copyButtonCGPTDark"]))
demoScript = getCopiedText()

shortBreak()
NewIncognitoWindow()
shortBreak()
getFocusOnChromeUrlBox()
miniBreak()
paste("temp-mail.org")
miniBreak()
press("enter")
customBreak(20)
click(getPos("copymailbutton"))
shortBreak()
temporary_email = getAndSaveEmail()
#phase 2
openNewTab()
miniBreak()
getFocusOnChromeUrlBox()
miniBreak()
paste("https://ai.invideo.io/login")
miniBreak()
press("enter")
longBreak()
#phase 3
click(getPos("invideoAiEmailInputButton"))
miniBreak()
paste(temporary_email)
miniBreak()
pressEnter()
longBreak()


#phase 4 --Go to tempmail tab back and open the mail sent by invideo

mediumBreak()
verification_code = ''
miniBreak()
goBackToTempMailTab()
miniBreak()
goDown(11)
miniBreak()
click(getPos(["invideoAiEmailInputButtonWhileHovered","mailFromInvideoAiTitle"]))


#phase 5 -- Get verification code

longBreak()
goDown(14)
miniBreak()
click(getPos("yourLoginCodeForInvideoAiText"), clicks=3, interval=0.2)
rawCodeText = getText()
verification_code = getNumberFromRawText(rawCodeText)
print("Successfully got the Verification code. The text is: " + verification_code)

#phase 6 -- Go to invideo tab > Find the verification code input box > paste the verification code and click continue

goToInvideoTab()
miniBreak()
click(getPos("invideoLoginCodeTextBox"))
miniBreak()
paste(verification_code)
miniBreak()
click(getPos("invideoLoginButton"))

#phase 7 -- Fill up all needed information in invideo

mediumBreak()
click(getPos(["toKnowAboutInvideoAiHow", "toKnowAboutInvideoAiHowBlue"]))
miniBreak()
click(getPos("continueButton1"))
shortBreak()
click(getPos("optionCButton"))
miniBreak()
click(getPos("continueButton1"))
mediumBreak()
click(getPos("whatShouldWeCallYouInvideoBoxName"))
miniBreak()
paste("SRS")
shortBreak()
click(getPos("continueButton2"))

#phase 8 - fillup the video requirements
mainText = "Create a video using exactly this script"+ demoScript +" \n Make the background music Explainer video backgrounds \n Settings: Use a male voice with a deep, slow and haunting accent. Don't add subtitles. Don't use iStock."
longBreak()
click(getPos("topicBox"))
miniBreak()
paste(mainText)
shortBreak()
click(getPos("generateVideoButton1"))
shortBreak()


click(getPos(["continuetoFinalStep","continuetoFinalStepNo"]))


click(getPos("exportButton1"))
miniBreak()
click(getPos("exportButton2"))
shortBreak()
click(getPos("stockWatermarks"))
miniBreak()
click(getPos("brandingButton"))
shortBreak()
click(getPos("continueFinalButton"))
exportPreparebreak()
previous_file_name = get_latest_file()
pressEnter()
finalExportBreak()
gatherVideoFromDownloads()


input_video_path = "input_video.mp4"  
output_video_path_after_cropping = "outputAfterCrop.mp4"
final_output = "outputFinal.mp4"

crop_video(input_video_path, output_video_path_after_cropping)
cut_off_last_seconds(output_video_path_after_cropping, final_output)

closeCurrentWindow()


click(getPos(["AiVoiceIconOpened", "AiVoiceIcon"]))
longBreak()
longBreak()
click(getPos("speechifySelectAllButton"))
shortBreak()
click(getPos("speechifyDeleteButton", "scrollUp"))
shortBreak()
click(getPos("speechifyAddABlockButton"))
shortBreak()
textBoxBtn = getPos("speechifyAddTextHereBoxButton")
click(textBoxBtn)
shortBreak()
click(textBoxBtn)
miniBreak()
paste(demoScript)
longBreak()
click(x=804,y=391)
miniBreak()
click(x=778,y=391+50)
miniBreak()
click(x=778,y=391-50)
miniBreak()
for i in range(0,12):
    click(x=778,y=492)
    miniBreak()
    click(x=778,y=492+50)
    miniBreak()
    click(x=778,y=492-50)
    shortBreak()
click(getPos("speechifyAddABlockButton"))
shortBreak()
textBoxBtn = getPos("speechifyAddTextHereBoxButton")
click(textBoxBtn)
longBreak()
click(104,666, clicks=5, interval=1)
mediumBreak()
startRecording()
click(getPos("speechifyPlayButton"))
shortBreak()
click(getPos("speechifyPlayButton"))
stopRecording()
closeCurrentWindow()

replaceSoundFromVideo(final_output, "my_audio.wav")












import sounddevice as sd
from scipy.io.wavfile import write
import numpy as np
from time import sleep

def record_screen_audio(filename="recording.wav", fs=100000):
    """Records screen audio until the 'q' key is pressed and saves it to a WAV file."""

    try:
        device_index = 0  # Assuming the default device is at index 0

        # Define a callback function for handling audio data
        def callback(indata, frames, time, status):
            recording.append(indata.copy())

        # Start recording
        with sd.InputStream(samplerate=fs, device=device_index, channels=2, callback=callback):
            recording = []
            print("Recording started. Press 'q' to stop.")
            while open("booleanFile2.txt", 'r').read() == "false":
                sleep(0.1)
            open("booleanFile2.txt", 'w').write("false")
            print("Recording stopped.")

        # Save the recorded audio to a WAV file
        write(filename, fs, np.concatenate(recording))

        print(f"Audio recording saved to {filename}")

    except Exception as e:
        print(f"Error during recording: {e}")

# Example usage:
while True:
    while open("booleanFile.txt", 'r').read() == "false":
        sleep(0.1)
    open("booleanFile.txt", 'w').write("false")
    record_screen_audio(filename="my_audio.wav")


Comments

Popular posts from this blog

Husband's Affair with Step Daughter Ends in Grisly Murder (True Crime Documentary)