Skip to content
This repository was archived by the owner on May 25, 2022. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions projects/Convert-Into-MoresCode/Code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import sys
import pygame
import time

#These are the dots and dashes or dits and dahs correspond to the alphabet

CODE = {'A': '.-', 'B': '-...', 'C': '-.-.',
'D': '-..', 'E': '.', 'F': '..-.',
'G': '--.', 'H': '....', 'I': '..',
'J': '.---', 'K': '-.-', 'L': '.-..',
'M': '--', 'N': '-.', 'O': '---',
'P': '.--.', 'Q': '--.-', 'R': '.-.',
'S': '...', 'T': '-', 'U': '..-',
'V': '...-', 'W': '.--', 'X': '-..-',
'Y': '-.--', 'Z': '--..',

'0': '-----', '1': '.----', '2': '..---',
'3': '...--', '4': '....-', '5': '.....',
'6': '-....', '7': '--...', '8': '---..',
'9': '----.'
}

ONE_UNIT = 0.5
THREE_UNITS = 3 * ONE_UNIT
SEVEN_UNITS = 7 * ONE_UNIT
PATH = 'morse_sound_files/' #The path of the audio file

#The method Verifies that there shouldn't be any special characters
def verify(string):
keys = CODE.keys()
for char in string:
if char.upper() not in keys and char != ' ':
sys.exit('Error the charcter ' + char + ' cannot be translated to Morse Code')

def main():

print('Welcome to Alphabet to Morse Code Translator v.01\n')

msg = input('Enter Message: ')
verify(msg)
print
pygame.init()
fi=[]
for char in msg:
if char == ' ':
print (' '*7,
time.sleep(SEVEN_UNITS))
else:
print (CODE[char.upper()],
pygame.mixer.music.load(PATH + char.upper() + '_morse_code.ogg'))
pygame.mixer.music.play()
time.sleep(THREE_UNITS)
temp=CODE[char.upper()],pygame.mixer.music.load(PATH + char.upper() + '_morse_code.ogg')
fi.append(temp)


actualCode,noneList=zip(*fi) #unzipped the list here into two list to get the final Mores Code at the end

print("Your Moores Code:",''.join(actualCode))
print ('\n\nGoodbye!')



if __name__ == "__main__":
main()
35 changes: 35 additions & 0 deletions projects/Convert-Into-MoresCode/Requirement.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

## The Libraries Required are :

1. Sys
2. pygame
3. time
## Pygame Installation
### Install pygame in Windows

Before installing Pygame, Python should be installed in the system, and it is good to have 3.6.1 or above version because it is much friendlier to beginners, and additionally runs faster. There are mainly two ways to install Pygame, which are given below:

**1. Installing through pip:** The good way to install Pygame is with the pip tool (which is what python uses to install packages). The command is the following:

1. py -m pip install -U pygame --user

**2. Installing through an IDE:** The second way is to install it through an IDE and here we are using Pycharm IDE. Installation of pygame in the pycharm is straightforward. We can install it by running the above command in the terminal or use the following steps:

- Open the **File** tab and click on the **Settings** option.

<img src="https://static.javatpoint.com/tutorial/pygame/images/pygame-installation.png">

- Select the **Project Interpreter** and click on the **+** icon.

<img src="https://static.javatpoint.com/tutorial/pygame/images/pygame-installation2.png">

- It will display the search box. Search the pygame and click on the **install package** button.
<img src="https://static.javatpoint.com/tutorial/pygame/images/pygame-installation3.png">

To check whether the pygame is properly installed or not, in the IDLE interpreter, type the following command and press Enter:

import pygame

If the command runs successfully without throwing any errors, it means we have successfully installed Pygame and found the correct version of IDLE to use for pygame programming.

<img src="https://static.javatpoint.com/tutorial/pygame/images/pygame-installation4.png">
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 4 additions & 0 deletions projects/Convert-Into-MoresCode/morse_sound_files/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
The files were downloaded from <a href="http://commons.wikimedia.org/wiki/Morse_code">WikiMedia Commons Morse Code</a>.



Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
17 changes: 17 additions & 0 deletions projects/Convert-Into-MoresCode/morse_sound_files/play_ogg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#############################################
# #
# http://www.thelivingpearl.com #
# #
# was wrriten by Captain DeadBones #
# #
# cpt@thelivingpearl.com #
# #
#############################################

import pygame
import time

pygame.init()
pygame.mixer.music.load('A_morse_code.ogg')
pygame.mixer.music.play()
time.sleep(1.5)
4 changes: 4 additions & 0 deletions projects/Convert-Into-MoresCode/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## Introduction
**Morse code** is a method used in Telecommunication to Encode Text characters as standardized sequences of two different signal durations, called _dots_ and _dashes_ or _dits_ and _dahs_.

<img src ="https://upload.wikimedia.org/wikipedia/commons/thumb/b/b5/International_Morse_Code.svg/600px-International_Morse_Code.svg.png">