Skip to main content
added 14 characters in body
Source Link
Kasturi
  • 49
  • 1
  • 7

It was fun thinking some ways to make it sound more like baby.

import random
import re


baby_add_ons = [
    " no sweepy!",
    " teddy pwease?",
    " miwkies?",
    " nappy time?",
    " hug pwease?",
    ""
]

def to_baby_talk(text):
    def replace_word(word):
        word = re.sub(r'[rl]', 'w', word)
        word = re.sub(r'[RL]', 'W', word)
        word = re.sub(r'th', 'd', word)
        word = re.sub(r'Th', 'D', word)
        word = re.sub(r'TH', 'D', word)
        word = re.sub(r'ing\b', 'in’', word)
        return word

    def babyify_sentence(sentence):
        sentence = sentence.strip()
        words = sentence.split()
        baby_words = [replace_word(word) for word in words]
        baby_sentence = ' '.join(baby_words)

        if sentence.endswith(('.', '?', '!')):
            addon = random.choice(baby_add_ons)
            baby_sentence += addon
        return baby_sentence

    sentences = re.split(r'(?<=[.?!])\s+', text.strip())
    baby_text = ' '.join(babyify_sentence(sentence) for sentence in sentences)

    return baby_text

# Example usage
original_text = '''
Then the two animals stood and regarded each other cautiously.

"Hullo, Mole!" said the Water Rat.

"Hullo, Rat!" said the Mole.

"Would you like to come over?" enquired the Rat presently.

"Oh, it's all very well to talk," said the Mole rather pettishly, he being new to a river and riverside life and its ways.

"This has been a wonderful day!" said he, as the Rat shoved off and took to the sculls again. "Do you know, I've never been in a boat before in all my life."
'''

baby_text = to_baby_talk(original_text)
print(baby_text)
import random
import re


baby_add_ons = [
    " no sweepy!",
    " teddy pwease?",
    " miwkies?",
    " nappy time?",
    " hug pwease?",
    ""
]

def to_baby_talk(text):
    def replace_word(word):
        word = re.sub(r'[rl]', 'w', word)
        word = re.sub(r'[RL]', 'W', word)
        word = re.sub(r'th', 'd', word)
        word = re.sub(r'Th', 'D', word)
        word = re.sub(r'TH', 'D', word)
        word = re.sub(r'ing\b', 'in’', word)
        return word

    def babyify_sentence(sentence):
        sentence = sentence.strip()
        words = sentence.split()
        baby_words = [replace_word(word) for word in words]
        baby_sentence = ' '.join(baby_words)

        if sentence.endswith(('.', '?', '!')):
            addon = random.choice(baby_add_ons)
            baby_sentence += addon
        return baby_sentence

    sentences = re.split(r'(?<=[.?!])\s+', text.strip())
    baby_text = ' '.join(babyify_sentence(sentence) for sentence in sentences)

    return baby_text

# Example usage
original_text = '''
Then the two animals stood and regarded each other cautiously.

"Hullo, Mole!" said the Water Rat.

"Hullo, Rat!" said the Mole.

"Would you like to come over?" enquired the Rat presently.

"Oh, it's all very well to talk," said the Mole rather pettishly, he being new to a river and riverside life and its ways.

"This has been a wonderful day!" said he, as the Rat shoved off and took to the sculls again. "Do you know, I've never been in a boat before in all my life."
'''

baby_text = to_baby_talk(original_text)
print(baby_text)

It was fun thinking some ways to make it sound more like baby.

import random
import re


baby_add_ons = [
    " no sweepy!",
    " teddy pwease?",
    " miwkies?",
    " nappy time?",
    " hug pwease?",
    ""
]

def to_baby_talk(text):
    def replace_word(word):
        word = re.sub(r'[rl]', 'w', word)
        word = re.sub(r'[RL]', 'W', word)
        word = re.sub(r'th', 'd', word)
        word = re.sub(r'Th', 'D', word)
        word = re.sub(r'TH', 'D', word)
        word = re.sub(r'ing\b', 'in’', word)
        return word

    def babyify_sentence(sentence):
        sentence = sentence.strip()
        words = sentence.split()
        baby_words = [replace_word(word) for word in words]
        baby_sentence = ' '.join(baby_words)

        if sentence.endswith(('.', '?', '!')):
            addon = random.choice(baby_add_ons)
            baby_sentence += addon
        return baby_sentence

    sentences = re.split(r'(?<=[.?!])\s+', text.strip())
    baby_text = ' '.join(babyify_sentence(sentence) for sentence in sentences)

    return baby_text

# Example usage
original_text = '''
Then the two animals stood and regarded each other cautiously.

"Hullo, Mole!" said the Water Rat.

"Hullo, Rat!" said the Mole.

"Would you like to come over?" enquired the Rat presently.

"Oh, it's all very well to talk," said the Mole rather pettishly, he being new to a river and riverside life and its ways.

"This has been a wonderful day!" said he, as the Rat shoved off and took to the sculls again. "Do you know, I've never been in a boat before in all my life."
'''

baby_text = to_baby_talk(original_text)
print(baby_text)
Source Link
Kasturi
  • 49
  • 1
  • 7

import random
import re


baby_add_ons = [
    " no sweepy!",
    " teddy pwease?",
    " miwkies?",
    " nappy time?",
    " hug pwease?",
    ""
]

def to_baby_talk(text):
    def replace_word(word):
        word = re.sub(r'[rl]', 'w', word)
        word = re.sub(r'[RL]', 'W', word)
        word = re.sub(r'th', 'd', word)
        word = re.sub(r'Th', 'D', word)
        word = re.sub(r'TH', 'D', word)
        word = re.sub(r'ing\b', 'in’', word)
        return word

    def babyify_sentence(sentence):
        sentence = sentence.strip()
        words = sentence.split()
        baby_words = [replace_word(word) for word in words]
        baby_sentence = ' '.join(baby_words)

        if sentence.endswith(('.', '?', '!')):
            addon = random.choice(baby_add_ons)
            baby_sentence += addon
        return baby_sentence

    sentences = re.split(r'(?<=[.?!])\s+', text.strip())
    baby_text = ' '.join(babyify_sentence(sentence) for sentence in sentences)

    return baby_text

# Example usage
original_text = '''
Then the two animals stood and regarded each other cautiously.

"Hullo, Mole!" said the Water Rat.

"Hullo, Rat!" said the Mole.

"Would you like to come over?" enquired the Rat presently.

"Oh, it's all very well to talk," said the Mole rather pettishly, he being new to a river and riverside life and its ways.

"This has been a wonderful day!" said he, as the Rat shoved off and took to the sculls again. "Do you know, I've never been in a boat before in all my life."
'''

baby_text = to_baby_talk(original_text)
print(baby_text)