Beispiel #1
0
    def run(self):
        start = time.time()
        paused_start_time = None
        elapsed_paused = 0.0
        self.stopped = False
        morse_sound = sound.MorseSoundPlayer()
        self.elapsed_seconds = 0.0
        self.full_run_completed = False
        valid_letters = KOCH_LETTER_ORDER[:self.num_characters]
        if self.justlast:
            valid_letters = valid_letters[-self.justlast:]
        while self.elapsed_seconds < config.MINUTES_OF_TRAINING * 60.0:
            if self.stopped:
                break
            if self.paused:
                if not paused_start_time:
                    paused_start_time = time.time()
                time.sleep(0.5)
                elapsed_paused += time.time() - paused_start_time
                continue
            else:
                paused_start_time = None
            word = self.make_word(valid_letters)
            morse_sound.text_to_sound(word)
            self.elapsed_seconds = time.time() - start - elapsed_paused
            self.render_correct_answer(word)

        else:
            if not self.justlast:
                # don't log situations when user is just focusing on most recent letters.
                self.full_run_completed = True

        morse_sound.stop()
Beispiel #2
0
from morsecodelib import sound as morseSound
from morsecodelib.config import config as morseConfig

import sys
import time
import random
import os

if len(sys.argv) != 3:
    print("Usage: python morse.py wpm tone_freq")
    sys.exit(1)

morseConfig.WORDS_PER_MINUTE = int(sys.argv[1])
morseConfig.FREQUENCY = int(sys.argv[2])

player = morseSound.MorseSoundPlayer()
znaki = [
    "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "O", "M", "N",
    "O", "P", "Q", "R", "S", "T", "U", "W", "X", "Y", "Z", "1", "2", "3", "4",
    "5", "6", "7", "8", "9", "0"
]

while True:
    os.system('clear')
    znak = random.choice(znaki)
    print(znak)
    time.sleep(0.3)
    player.text_to_sound(znak)
    time.sleep(1)