User:Mxrwho/Lists
Playing with lists, sorting and randomization in python
Documentation
https://pad.xpub.nl/p/15424_lists -> https://pad.xpub.nl/p/15424_lists_m
export as plain text
Python code:
import random
def sort_and_format_text(text): words = text.split() words = [word.strip('*') for word in words] sorted_words = sorted(words) formatted_lines = [] current_line = [] for word in sorted_words: current_line.append(word) if len(current_line) >= 3 and len(current_line) <= 5: formatted_lines.append(' '.join(current_line)) current_line = [] if current_line: formatted_lines.append(' '.join(current_line)) return '\n'.join(formatted_lines)
def randomize_and_format_text(text): words = text.split() words = [word.strip('*') for word in words] random.shuffle(words) formatted_lines = [] current_line = [] for word in words: current_line.append(word) if len(current_line) >= 3 and len(current_line) <= 5: formatted_lines.append(' '.join(current_line)) current_line = [] if current_line: formatted_lines.append(' '.join(current_line)) return '\n'.join(formatted_lines)
with open('lists.txt', 'r') as file: input_text = file.read() print("Original text:", input_text)
sorted_text = sort_and_format_text(input_text) print("Sorted and formatted text (3 to 5 words per line):") print(sorted_text)
randomized_text = randomize_and_format_text(input_text) print("Randomized and formatted text (3 to 5 words per line):") print(randomized_text)
with open('alphalist.txt', 'w') as file: file.write(sorted_text)
with open('randylist.txt', 'w') as file: file.write(randomized_text)
print("Text saved to 'alphalist.txt' and 'randylist.txt'")
Combine texts and then:
say -o alllists.aiff -v Whisper -r 130 -f alllists.txt
and then:
ffmpeg -i alllists.aiff -codec:a libmp3lame -qscale:a 2 alllists.mp3