Data Communication and Computer Networks Project.
Data Communication and Computer Networks Project.
import winsound
import time
def text_to_morse(text):
morse_code = ''
for char in text.upper():
if char in morse_code_dict:
morse_code += morse_code_dict[char] + ' '
else:
morse_code += '/ ' # For non-alphanumeric characters
return morse_code
def play_morse_code(morse_code):
dot_duration = 100 # milliseconds
dash_duration = 4 * dot_duration
gap_duration = dot_duration
word_gap_duration = 8 * dot_duration
for symbol in morse_code:
if symbol == '.':
winsound.Beep(440, dot_duration)
time.sleep(gap_duration / 1000)
elif symbol == '-':
winsound.Beep(440, dash_duration)
time.sleep(gap_duration / 1000)
elif symbol == '/':
time.sleep(word_gap_duration / 1000)
else:
time.sleep(gap_duration / 1000)
if __name__ == "__main__":
text = input("Enter the text to convert to Morse code: ")
morse_code = text_to_morse(text)
print("Morse Code:", morse_code)
play_morse_code(morse_code)
Below is a sample Paragraph
English:
Data communication is the process of exchanging information between two or more devices
through a transmission medium such as wires, cables, or wireless signals. It involves encoding
data into signals that can be transmitted and decoding them upon reception. This exchange
enables the transfer of text, images, audio, and video across various communication networks,
facilitating seamless connectivity and information sharing in our digital world.
Morse Code:
-.. .- - .- / -.-. --- -- -- ..- -. .. -.-. .- - .. --- -. / .. ... / - .... . / .--. .-. --- -.-. . ... ... / --- ..-. / . -..- -.-. .... .- -.
--. .. -. --. / .. -. ..-. --- .-. -- .- - .. --- -. / -... . - .-- . . -. / - .-- --- / --- .-. / -- --- .-. . / -.. . ...- .. -.-. . ... / -
.... .-. --- ..- --. .... / .- / - .-. .- -. ... -- .. ... ... .. --- -. / -- . -.. .. ..- -- / ... ..- -.-. .... / .- ... / .-- .. .-. . ... / /
-.-. .- -... .-.. . ... / / --- .-. / .-- .. .-. . .-.. . ... ... / ... .. --. -. .- .-.. ... / / .. - / .. -. ...- --- .-.. ...- . ... / . -. -.-.
--- -.. .. -. --. / -.. .- - .- / .. -. - --- / ... .. --. -. .- .-.. ... / - .... .- - / -.-. .- -. / -... . / - .-. .- -. ... -- .. - - . -.. /
.- -. -.. / -.. . -.-. --- -.. .. -. --. / - .... . -- / ..- .--. --- -. / .-. . -.-. . .--. - .. --- -. / / - .... .. ... / . -..- -.-. .... .-
-. --. . / . -. .- -... .-.. . ... / - .... . / - .-. .- -. ... ..-. . .-. / --- ..-. / - . -..- - / / .. -- .- --. . ... / / .- ..- -.. .. --- /
/ .- -. -.. / ...- .. -.. . --- / .- -.-. .-. --- ... ... / ...- .- .-. .. --- ..- ... / -.-. --- -- -- ..- -. .. -.-. .- - .. --- -. / -. . -
.-- --- .-. -.- ... / / ..-. .- -.-. .. .-.. .. - .- - .. -. --. / ... . .- -- .-.. . ... ... / -.-. --- -. -. . -.-. - .. ...- .. - -.-- / .- -.
-.. / .. -. ..-. --- .-. -- .- - .. --- -. / ... .... .- .-. .. -. --. / .. -. / --- ..- .-. / -.. .. --. .. - .- .-.. / .-- --- .-. .-.. -..