User:Mxrwho/Lists: Difference between revisions
No edit summary |
No edit summary |
||
Line 42: | Line 42: | ||
formatted_lines.append(' '.join(current_line)) | formatted_lines.append(' '.join(current_line)) | ||
return '\n'.join(formatted_lines) | return '\n'.join(formatted_lines) | ||
with open('lists.txt', 'r') as file: | with open('lists.txt', 'r') as file: | ||
Line 48: | Line 47: | ||
print("Original text:", input_text) | print("Original text:", input_text) | ||
sorted_text = sort_and_format_text(input_text) | sorted_text = sort_and_format_text(input_text) | ||
print("Sorted and formatted text (3 to 5 words per line):") | print("Sorted and formatted text (3 to 5 words per line):") | ||
print(sorted_text) | print(sorted_text) | ||
randomized_text = randomize_and_format_text(input_text) | randomized_text = randomize_and_format_text(input_text) | ||
Line 61: | Line 58: | ||
Combined texts and then: | Combined texts and then: | ||
say -o alllists.aiff -v Whisper -r 130 -f alllists.txt | say -o alllists.aiff -v Whisper -r 130 -f alllists.txt | ||
and then: | and then: | ||
ffmpeg -i alllists.aiff -codec:a libmp3lame -qscale:a 2 alllists.mp3 | ffmpeg -i alllists.aiff -codec:a libmp3lame -qscale:a 2 alllists.mp3 |
Revision as of 13:29, 19 April 2024
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)
Combined 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