Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • 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.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • 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

Gold 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 :)
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom