• Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Fun activity Anyone want to make a speech to text

simong1993

King Coder
Staff Team
Guardian
Hey all, i have a few things going on but i am wondering if any python programmers want to join me with this little adventure, I want to colab and make a text to speech video :D I have done some code already but its always nice to have someone to bounce off
 
Python:
import gtts
from playsound2 import playsound
from bs4 import BeautifulSoup
import requests

#GetFacts
page = requests.get("http://www.djtech.net/humor/useless_facts.htm", timeout=1)
soup = BeautifulSoup(page.text, 'html.parser')

souptable = soup.find("table", {"id": "table269"})

for loop in souptable.findAll('p'):
    try:
        TextEnd = ""
        TextEndComplete = ""
        Fact = loop.text.strip()
        Fact = Fact.strip()
        CompleteText = Fact
        CompleteText = CompleteText.replace('\n', '').replace('\r', '').replace('        ', '')

        if len(CompleteText) > 50:
            CompleteText = CompleteText.split(" ")
            for i in CompleteText:
                if len(TextEnd) < 50:
                    TextEnd = TextEnd + i + " "
                else:
                    TextEndComplete = TextEndComplete + TextEnd + i + "\n"
                    TextEnd = ""
            if TextEnd != "":
                TextEndComplete = TextEndComplete + TextEnd
                TextEnd = ""


            print(TextEndComplete)
        print("=============")

        tts = gtts.gTTS(CompleteText)
        tts.save("FactVideo1.mp3")
        playsound("FactVideo1.mp3")

    except Exception as E:
        print(E)

this is where i am at, at the moment. i take a quote and if its over 50 words i split it by the space. put it back together and put it on a new line every 50 characters :)
 
Top Bottom