Skip to content

Instantly share code, notes, and snippets.

@weakish
Created April 3, 2011 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weakish/900426 to your computer and use it in GitHub Desktop.
Save weakish/900426 to your computer and use it in GitHub Desktop.
A minimalistic recite words command line tool in #python.

wmrws/wmrwoid is a minimalistic recite words tool for consoles on unixen including android.

Features

  • command line (fast and convinient)
  • not based on translation (good for thinking in English)
  • use plain text files as word lists

Requirements

  • Python (2.5+)
  • espeak (if not Mac OS X or Android)

Usage

Recite words in your own way. Then put them in a text file for reviews and tests. (One word per line, and ASCII only.) You can have multiple word lists. Just use multiple text files.

In review, words will be read out. Word lists in the current working directory will be used. (Android version is hard coded to /sdcard/wmrwoid/.)

In test, you need to listen and write down words. If you made a mistake, it will display the correct spelling, and wait for you to press 'Return' to continue. It will display Ready? when the first run finished. Press 'Return' to continue to the second run, in which it will test misspelled words in the first run. Then it goes to the third run, until you spelled all words correctly. For ease of typing, the test program is case insensitive.

Type wmrws.py -h or ?(android version) for more information.

Limits of the android version

  • No readline support.
  • Only review all word lists in /sdcard/wmrwoid/, cannot review single list or specify intervals.
  • Only test the most recent/latest word list, cannot test old lists.

If you don't like 2nd and 3rd limits, it's easy to alter the script. The logic is already in Review and Test functions, you just need to implement the UI part.

However, android version has a special option -p, which will read out words you input consecutively. If you miss this feature, you may try repl espeak outside android.

Feedback

Feel free to comment and fork!

https://gist.github.com/900426

Flattr this

Changlog

wmrws.py 0.0.2: released on 2011-06-10

  • remove Pronounce()

wmrws.py 0.0.1

  • clean up
#!python2.6.2
'''wmrws's android port
wmrws is Weakish's Minimalistic Recite Words System
(c) 2009-2011 Jakukyo Friel <weakish@gmail.com>
This program is licensed under GPL v2.
https://gist.github.com/900426
'''
import glob
import subprocess
import sys
import time
from os.path import getmtime
import android
droid = android.Android()
# core functions
def Review(wordlist, interval):
'''Review your wordlist.
Speak out the first word on the list. Then give you sometime to review
the word. Then continue to next word until the end of the list.
'''
def ReviewWord(word, interval):
print word
SayWord(word)
Sleep(interval) # a good time to recite the word
map(ReviewWord, wordlist, [interval]*len(wordlist))
def Test(wordlist):
'''Test your wordlist.
Speak out the word without displaying it. You input the words. If
your spell is correct, continue to next word. If wrong, display the
correct spelling and give you sometime to memorize it. At the end,
retest those words you spelled wrongly.
'''
if wordlist == []:
print 'Done.'
else:
def TestWord(word):
SayWord(word)
input = raw_input('; ') # well, I am a fan of rc
if input.lower() == word.lower(): # I'm very lazy to type Caps.
pass
else:
weakWordlist.append(word) # prepare for rerecite
print word
Sleep(-1)
weakWordlist = []
print "Ready?"
Sleep(-1)
map(TestWord, wordlist)
Test(weakWordlist)
def Pronounce():
print 'Type a word. (Type q to quit.)'
while True:
word = raw_input('; ')
if word == 'q': break
else: SayWord(word)
print 'Already shut up.'
def SayWord(word):
droid.ttsSpeak(word)
def Sleep(interval):
if interval < 0: # hold until someone press Enter
raw_input()
else:
time.sleep(interval)
# Info
def Help():
print '''
wmrwoid a minimalistic recite words tool for Android
Options:
r review all wordfiles in /sdcard/wmrwoid/
t test the newest file in /sdcard/wmrwoid/
p pronounce words
q quit
? print this help page
You need Python for Android (SL4A) to run this script.
WORDFILE requires:
* one word/phrase per line
* only support ASCII characters
* not support Windows/DOS text file
Tips: you can use volume keys to increase font size in SL4A.
'''
def Wordify(wordFile):
'''convert wordlist files (one word/phrase per line) to lists'''
return [line.strip('\n') for line in open(wordFile).readlines()]
# note we strip the newline character.
# main program
def main():
opt = raw_input('?[rtpq?]: ')
if opt == 'r':
for i in glob.glob('/sdcard/wmrwoid/*'):
Review(Wordify(i), 2)
main()
elif opt == 't':
Test(Wordify(max(glob.glob('/sdcard/wmrwoid/*'), key=getmtime)))
main()
elif opt == 'p':
Pronounce()
main()
elif opt == 'q':
print 'Goodbye!'
else:
Help()
main()
if __name__ == '__main__':
main()
#!/usr/bin/env python2.5
'''wmrws is Weakish's Minimalistic Recite Words System
On Darwin, it uses Mac OS X built-in Speech Synthesis manager.
On other OS, it uses espeak.
(c) 2009-2011 Jakukyo Friel <weakish@gmail.com>
This program is licensed under GPL v2.
https://gist.github.com/900426
'''
import glob
import readline
import subprocess
import sys
import time
from os.path import getmtime
# core functions
def Review(wordlist, interval):
'''Review your wordlist.
Speak out the first word on the list. Then give you sometime to review
the word. Then continue to next word until the end of the list.
'''
def ReviewWord(word, interval):
subprocess.call(['clear']) # focus on one word
print word
SayWord(word)
Sleep(interval) # a good time to recite the word
map(ReviewWord, wordlist, [interval]*len(wordlist))
def Test(wordlist):
'''Test your wordlist.
Speak out the word without displaying it. You input the words. If
your spell is correct, continue to next word. If wrong, display the
correct spelling and give you sometime to memorize it. At the end,
retest those words you spelled wrongly.
'''
if wordlist == []:
print 'Done.'
else:
def TestWord(word):
SayWord(word)
input = raw_input('; ') # well, I am a fan of rc
if input.lower() == word.lower(): # I'm very lazy to type Caps.
pass
else:
weakWordlist.append(word) # prepare for rerecite
print word
Sleep(-1)
weakWordlist = []
print "Ready?"
Sleep(-1)
map(TestWord, wordlist)
Test(weakWordlist)
def SayWord(word):
if sys.platform == 'darwin':
subprocess.call(['say', word])
else:
subprocess.call(['espeak', word])
def Sleep(interval):
if interval < 0: # hold until someone press Enter
raw_input()
else:
time.sleep(interval)
# Info
def Help():
print '''
wmrws a minimalistic recite words tool
Options:
-r WORDFILE INTERVALSECONDS review
-r WORDFILE review (with 1 second interval)
-r review all wordfiles in current directory
-t WORDFILE test
-t test the newest file in current directory
-h print this help page
-v print version
WORDFILE requires:
* one word/phrase per line
* only support ASCII characters
* not support Windows/DOS text file
'''
def semver():
print '''
wmrws 0.0.2 released on 2011-06-11
'''
# Exceptions
def HelpExit():
'''Don't understand the input. Print help page.'''
Help()
sys.exit()
# process arguments and return the corresponding function
def ProcOpts(args):
l = len(args)
opt = args[1]
if opt == '-r':
if l == 4:
Review(Wordify(args[2]), eval(args[3]))
elif l == 3:
Review(Wordify(args[2]), 1)
elif l == 2:
for i in glob.glob('*'):
Review(Wordify(i), 1)
else:
HelpExit()
elif opt == '-t':
if l == 3:
Test(Wordify(args[2]))
if l == 2:
Test(Wordify(max(glob.glob('*'), key=getmtime)))
else:
HelpExit()
elif opt == '-h':
Help()
elif opt == '-v':
semver()
else:
HelpExit()
def Wordify(wordFile):
'''convert wordlist files (one word/phrase per line) to lists'''
return [line.strip('\n') for line in open(wordFile).readlines()]
# note we strip the newline character.
# main program
def main():
if len(sys.argv) < 2: HelpExit()
else: ProcOpts(sys.argv)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment