from waysToReach import *
this_page, this_browser, this_play, this_state = None, None, None, False
open("speech/completed.txt", 'w').write("False")
text = open("speech/text.txt", 'r').read()
output_path = open("speech/output_path.txt", 'r').read()
artist_name = open("speech/artist_name.txt", 'r').read()
# pitches = ["Low", "Extra Low", "Medium", "High", "Extra High"]
pitch = open("speech/pitch.txt", 'r').read()
style = open("speech/style.txt", 'r').read()
try:
PAGE, BROWSER, PLAY = create_browser(
"https://app.clipchamp.com/editor/67de3442-9ac1-48ec-8bc4-9786a0af9768",
data="clipchamp",
is_visible=True
)
this_page, this_browser, this_play = PAGE, BROWSER, PLAY
PAGE.wait_for_load_state("domcontentloaded")
PAGE.wait_for_timeout(5000)
func = """fetch(blobUrl).then(response => response.blob()).then(blob => {const mp3File = new File([blob], `${'test'}.mp3`, { type: 'audio/mpeg' }); const url = URL.createObjectURL(mp3File);const a = document.createElement('a');a.href = url;a.download = mp3File.name;document.body.appendChild(a);a.click();setTimeout(() => {document.body.removeChild(a);URL.revokeObjectURL(url);}, 100);}).catch(error => {console.error('Error converting blob to MP3:', error);});"""
# PAGE.evaluate("""function convertBlobToMp3AndDownload(blobUrl, fileName) { fetch(blobUrl).then(response => response.blob()).then(blob => { const mp3File = new File([blob], `${fileName}.mp3`, { type: 'audio/mpeg' }); const url = URL.createObjectURL(mp3File); const a = document.createElement('a'); a.href = url; a.download = mp3File.name; document.body.appendChild(a); a.click(); setTimeout(() => { document.body.removeChild(a); URL.revokeObjectURL(url); }, 100); }).catch(error => { console.error('Error converting blob to MP3:', error); }); }""")
click_on(PAGE, "textContent", "Record & create", "button")
click_on(PAGE, "textContent", "Text to speech", "button", wait=10)
click_on(PAGE, "outerHTML", "language-dropdown", "button", wait=5)
PAGE.evaluate("""Array.from(document.querySelectorAll('div')).forEach(div => { if (div.textContent.includes('English (United States)')) { div.click(); } });""")
miniBreak()
click_on(PAGE, "outerHTML", "voice-dropdown", "button")
PAGE.evaluate("""Array.from(document.querySelectorAll('div')).forEach(div => { if (div.textContent.includes('""" + artist_name +"""')) { div.click(); } });""")
miniBreak()
click_on(PAGE, "textContent", "Advanced settings", "button")
click_on(PAGE, "textContent", "Default", "button")
PAGE.evaluate("""Array.from(document.querySelectorAll('div')).forEach(div => { if (div.textContent.includes('""" + pitch +"""')) { div.click(); } });""")
miniBreak()
# click_on(PAGE, "textContent", "Neutral", "button")
try:
PAGE.evaluate("""Array.from(document.querySelectorAll('div')).forEach(div => { if (div.textContent.includes('""" + style +"""')) { div.click(); } });""")
except:
print("This artist has no style.")
miniBreak()
click_on(PAGE, "outerHTML", "like to say", "textarea")
# PAGE.keyboard.type(script)
from pyperclip import copy
copy(text)
PAGE.keyboard.down("Control")
tinyBreak()
PAGE.keyboard.press("v")
tinyBreak()
PAGE.keyboard.up("Control")
miniBreak()
shortBreak()
def process_requests(response):
global this_page, this_browser, this_play, this_state
url = response.url
if "blob:https://app.clipchamp.com" in url and not this_state:
print(url)
with this_page.expect_download(timeout=10000000) as download_info:
if not this_state:
this_page.evaluate("""fetch('"""+url+"""').then(response => response.blob()).then(blob => {const mp3File = new File([blob], `${'test'}.mp3`, { type: 'audio/mpeg' }); const url = URL.createObjectURL(mp3File);const a = document.createElement('a');a.href = url;a.download = mp3File.name;document.body.appendChild(a);a.click();setTimeout(() => {document.body.removeChild(a);URL.revokeObjectURL(url);}, 100);}).catch(error => {console.error('Error converting blob to MP3:', error);});""")
this_state = True
download = download_info.value
download.save_as("C:\\Users\\Lenovo\\Desktop\\Automations\\" + output_path)
click_on(PAGE, "textContent", "New text to speech", "div")
this_page.keyboard.press("Delete")
longBreak()
this_page.close()
this_browser.close()
this_play.stop()
PAGE.on("response", process_requests)
PAGE.evaluate("""Array.from(document.querySelectorAll('button')).forEach(button => { if (button.textContent.includes('Preview')) { button.click(); } });""")
PAGE.wait_for_timeout(10000000)
except Exception as e:
print("Done: " + str(e))
open("speech/completed.txt", 'w').write("True")
Engine
Loading… Loading… Loading…
Comments
Post a Comment