SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2014-01-25 00:17:15

kols
#! CrunchBanger
From: Norway
Registered: 2013-03-22
Posts: 151

Bash Morse code Generator

This script generates Morse codes out of text input.

Suggestions? I'm happy to hear'em.

Do with it what you please!

EDIT: You will need to install "Beep" which makes the actual beeping sounds.

sudo apt-get install beep
#!/bin/bash

#script: Morse
#Written by Ole-Jørgen Næss Kolsrud

#Thanks to crunchbangers damo, ehde and aibo!
#Also, thank you, Internet=P

#Dependencies: bash, beep


echo "  " 
echo -e '\E[1;32m'"\033[1mMORSE CONVERTER\033[0m"
echo "  "
echo "Usage: One word at a time, letters must be separated by a space"
echo "  "

while true
	do
		a=(1 100 1 300 0 0 0 0)
		b=(1 300 3 100 0 0 0 0)
		c=(1 300 1 100 1 300 1 100)
		d=(1 300 2 100 0 0 0 0)
		e=(1 100 0 0 0 0 0 0)
		f=(2 100 1 300 1 100 0 0)
		g=(2 300 1 100 0 0 0 0)
		h=(4 100 0 0 0 0 0 0) 
		i=(2 100 0 0 0 0 0 0)
		j=(1 100 3 300 0 0 0 0)
		k=(1 100 1 300 1 100 0 0)
		l=(1 100 1 300 2 100 0 0)
		m=(2 300 0 0 0 0 0 0)
		n=(1 300 1 100 0 0 0 0)
		o=(3 300 0 0 0 0 0 0)
		p=(1 100 2 300 1 100 0 0)
		q=(2 300 1 100 1 300 0 0)
		r=(1 100 1 300 1 100 0 0)
		s=(3 100 0 0 0 0 0 0)
		t=(1 300 0 0 0 0 0 0)
		u=(2 100 1 300 0 0 0 0)
		v=(3 100 1 300 0 0 0 0)
		w=(1 100 2 300 0 0 0 0)
		x=(1 300 2 100 1 300 0 0)
	        y=(1 300 1 100 2 300 0 0)
		z=(2 300 2 100 0 0 0 0)
		
		read -p "Text to convert: " tekst_inn

		tekst_inn_ARRAY=(`echo $tekst_inn | tr " " "\n"`)

		an=0

		for ax in "${tekst_inn_ARRAY[@]}"
    	do
				bokstav[an]=$ax
				an=$an+1
		done
		
		bokstav_count=${#bokstav[@]}
		
		am=0

		while [ $am -le $bokstav_count ] ; do
				
				for as in ${bokstav[am]} 
					do 
  					eval 'morse0="${'"$as[0]"'}"'
  					eval 'morse1="${'"$as[1]"'}"'
  					eval 'morse2="${'"$as[2]"'}"'
					eval 'morse3="${'"$as[3]"'}"'
					eval 'morse4="${'"$as[4]"'}"'
					eval 'morse5="${'"$as[5]"'}"'
					eval 'morse6="${'"$as[6]"'}"'
					eval 'morse7="${'"$as[7]"'}"'
												
						beep -r $morse0 -d 300 -f 1000 -l $morse1 
						sleep 0.3
						beep -r $morse2 -d 300 -f 1000 -l $morse3 
						sleep 0.3
						beep -r $morse4 -d 300 -f 1000 -l $morse5 
						sleep 0.3
						beep -r $morse6 -d 300 -f 1000 -l $morse7 
				done
				((am=am+1))
		done
unset bokstav[@]
done

Last edited by kols (2014-01-25 02:51:40)


I mostly code at night. Mostly.

Offline

Help fund CrunchBang, donate to the project!

#2 2014-01-25 00:34:58

retf
#! CrunchBanger
From: On top of spaghetti
Registered: 2013-12-25
Posts: 200

Re: Bash Morse code Generator

I'll be happy to test it out...
Although - first suggestion is to add a license... GPLv3 is always my preference, but then again I could be RMS's long lost half-brother...

EDIT:
Second comment:
Depends on package 'beep'

So before program runs correctly you may need to:

sudo apt-get install beep

Third comment:
debugging still...

Last edited by retf (2014-01-25 00:39:08)

Offline

#3 2014-01-25 02:48:41

kols
#! CrunchBanger
From: Norway
Registered: 2013-03-22
Posts: 151

Re: Bash Morse code Generator

sudo apt-get install beep

Last edited by kols (2014-01-25 02:54:30)


I mostly code at night. Mostly.

Offline

#4 2014-01-25 03:21:36

damo
#! gimpbanger
From: N51.5 W002.8 (mostly)
Registered: 2011-11-24
Posts: 5,434

Re: Bash Morse code Generator

#!/bin/bash

echo -n "Enter alphanumeric input: "
read input

entry="$(echo $input | sed -e 's/[^[:alnum:]]//g')"

if [ "$entry" != "$input" ] ; then
    echo "Input not valid."
else
    echo "Input valid."
fi

Offline

#5 2014-01-25 03:30:11

kols
#! CrunchBanger
From: Norway
Registered: 2013-03-22
Posts: 151

Re: Bash Morse code Generator

#!/bin/bash

echo -n "Enter alphanumeric input: "
read input

entry="$(echo $input | sed -e 's/[^[:alnum:]]//g')"

if [ "$entry" != "$input" ] ; then
    echo "Input not valid."
else
    echo "Input valid."
fi

I mostly code at night. Mostly.

Offline

#6 2014-01-29 20:30:44

kols
#! CrunchBanger
From: Norway
Registered: 2013-03-22
Posts: 151

Re: Bash Morse code Generator

An update:

Inside while and then inside its for after all the "eval's" add this piece:

echo ${bokstav[am]}

This will print which letter is being processed by "beep" - a great addition for learning purposes!


I mostly code at night. Mostly.

Offline

#7 2014-02-10 17:44:54

kols
#! CrunchBanger
From: Norway
Registered: 2013-03-22
Posts: 151

Re: Bash Morse code Generator

UPDATE: More efficient, added numbers and a representation of the sound through dots and dashes

#!/bin/bash

#script: Morse
#Written by Ole-Jørgen Næss Kolsrud

#Thanks to crunchbangers damo, ehde and aibo!
#Also, thank you, Internet=P

#Dependencies: bash, beep


echo "  " 
echo -e '\E[1;32m'"\033[1mMORSE CONVERTER\033[0m"
echo "  "
echo "Usage: One word at a time, letters must be separated by a space"
echo "  "

read -p "Pause between letter parts [ms]: " letter_part_pause
read -p "Pause beetween letters [s]: " letter_pause

#Ett eller annet sted legger vi inn valget om man vil ha tilfeldige bokstaver, eller om man vil taste dem inn sjæl.


		a=(1 100 1 300 0 0 0 0 ".-")
		b=(1 300 3 100 0 0 0 0 "-...")
		c=(1 300 1 100 1 300 1 100 "-.-.")
		d=(1 300 2 100 0 0 0 0 "-..")
		e=(1 100 0 0 0 0 0 0 ".")
		f=(2 100 1 300 1 100 0 0 "..-.")
		g=(2 300 1 100 0 0 0 0 "--.")
		h=(4 100 0 0 0 0 0 0 "....") 
		i=(2 100 0 0 0 0 0 0 "..")
		j=(1 100 3 300 0 0 0 0 ".---")
		k=(1 100 1 300 1 100 0 0 ".-.")
		l=(1 100 1 300 2 100 0 0 ".-..")
		m=(2 300 0 0 0 0 0 0 "--")
		n=(1 300 1 100 0 0 0 0 "-.")
		o=(3 300 0 0 0 0 0 0 "---")
		p=(1 100 2 300 1 100 0 0 ".--.")
		q=(2 300 1 100 1 300 0 0 "--.-")
		r=(1 100 1 300 1 100 0 0 ".-.")
		s=(3 100 0 0 0 0 0 0 "...")
		t=(1 300 0 0 0 0 0 0 "-")
		u=(2 100 1 300 0 0 0 0 "..-")
		v=(3 100 1 300 0 0 0 0 "...-")
		w=(1 100 2 300 0 0 0 0 ".--")
		x=(1 300 2 100 1 300 0 0 "-..-")
	        y=(1 300 1 100 2 300 0 0 "-.--")
		z=(2 300 2 100 0 0 0 0 "--..")
		n1=(1 100 4 300 0 0 0 0 ".----")
		n2=(2 100 3 300 0 0 0 0 "..---")
		n3=(3 100 2 300 0 0 0 0 "...--")
		n4=(4 100 1 300 0 0 0 0 "....-")
		n5=(5 100 0 0 0 0 0 0 ".....")
		n6=(1 300 4 100 0 0 0 0 "-....")
		n7=(2 300 3 100 0 0 0 0 "--...")
		n8=(3 300 2 100 0 0 0 0 "---..")
		n9=(4 300 1 100 0 0 0 0 "----.")
		n0=(5 300 0 0 0 0 0 0 "-----")
		space=""

while true
	do

		
	  read -p "Text to convert: " tekst_inn

		tekst_inn_ARRAY=(`echo $tekst_inn | tr " " "\n"`) #Hva er tr? Hvorfor \n?

		an=0

		for ax in "${tekst_inn_ARRAY[@]}"
    	do
				bokstav[an]=$ax
				an=$an+1
		done
		
		bokstav_count=${#bokstav[@]}
		
		am=0

		while [ $am -le $bokstav_count ] ; do
				
				for as in ${bokstav[am]} #Hvordan kunne jeg ha ordna det sånn at $as kunne vært et helt array?
					do 
  					eval 'morse0="${'"$as[0]"'}"' #Jeg må lære hvorfor dette funker...
  					eval 'morse1="${'"$as[1]"'}"'
  					eval 'morse2="${'"$as[2]"'}"'
					eval 'morse3="${'"$as[3]"'}"'
					eval 'morse4="${'"$as[4]"'}"'
					eval 'morse5="${'"$as[5]"'}"'
					eval 'morse6="${'"$as[6]"'}"'
					eval 'morse7="${'"$as[7]"'}"'
					eval 'morse8="${'"$as[8]"'}"'

						echo "${bokstav[am]} $morse8"
						
						beep -r $morse0 -D $letter_part_pause -f 600 -l $morse1 2 > /dev/null #Kjører første gruppe
						beep -r $morse2 -D $letter_part_pause -f 600 -l $morse3 2 > /dev/null #Kjører andre gruppe
						beep -r $morse4 -D $letter_part_pause -f 600 -l $morse5 2 > /dev/null #Kjører tredje gruppe
						beep -r $morse6 -D $letter_part_pause -f 600 -l $morse7 2 > /dev/null #Kjører fjerde gruppe
						sleep $letter_pause


						

				done
				((am=am+1))
		done
unset bokstav[@]
done

I mostly code at night. Mostly.

Offline

#8 2014-04-17 17:18:51

FreakyTah
New Member
Registered: 2014-04-17
Posts: 1

Re: Bash Morse code Generator

#!/bin/bash

#script: Morse
#Written by Ole-Jørgen Næss Kolsrud

#Thanks to crunchbangers damo, ehde and aibo!
#Also, thank you, Internet=P

#Dependencies: bash, beep


echo "  " 
echo -e '\E[1;32m'"\033[1mMORSE CONVERTER\033[0m"
echo "  "
echo "Usage: One word at a time, letters must be separated by a space"
echo "  "

read -p "Pause between letter parts [ms]: " letter_part_pause
read -p "Pause beetween letters [s]: " letter_pause

#Ett eller annet sted legger vi inn valget om man vil ha tilfeldige bokstaver, eller om man vil taste dem inn sjæl.


		a=(1 100 1 300 0 0 0 0 ".-")
		b=(1 300 3 100 0 0 0 0 "-...")
		c=(1 300 1 100 1 300 1 100 "-.-.")
		d=(1 300 2 100 0 0 0 0 "-..")
		e=(1 100 0 0 0 0 0 0 ".")
		f=(2 100 1 300 1 100 0 0 "..-.")
		g=(2 300 1 100 0 0 0 0 "--.")
		h=(4 100 0 0 0 0 0 0 "....") 
		i=(2 100 0 0 0 0 0 0 "..")
		j=(1 100 3 300 0 0 0 0 ".---")
		k=(1 100 1 300 1 100 0 0 ".-.")
		l=(1 100 1 300 2 100 0 0 ".-..")
		m=(2 300 0 0 0 0 0 0 "--")
		n=(1 300 1 100 0 0 0 0 "-.")
		o=(3 300 0 0 0 0 0 0 "---")
		p=(1 100 2 300 1 100 0 0 ".--.")
		q=(2 300 1 100 1 300 0 0 "--.-")
		r=(1 100 1 300 1 100 0 0 ".-.")
		s=(3 100 0 0 0 0 0 0 "...")
		t=(1 300 0 0 0 0 0 0 "-")
		u=(2 100 1 300 0 0 0 0 "..-")
		v=(3 100 1 300 0 0 0 0 "...-")
		w=(1 100 2 300 0 0 0 0 ".--")
		x=(1 300 2 100 1 300 0 0 "-..-")
	        y=(1 300 1 100 2 300 0 0 "-.--")
		z=(2 300 2 100 0 0 0 0 "--..")
		n1=(1 100 4 300 0 0 0 0 ".----")
		n2=(2 100 3 300 0 0 0 0 "..---")
		n3=(3 100 2 300 0 0 0 0 "...--")
		n4=(4 100 1 300 0 0 0 0 "....-")
		n5=(5 100 0 0 0 0 0 0 ".....")
		n6=(1 300 4 100 0 0 0 0 "-....")
		n7=(2 300 3 100 0 0 0 0 "--...")
		n8=(3 300 2 100 0 0 0 0 "---..")
		n9=(4 300 1 100 0 0 0 0 "----.")
		n0=(5 300 0 0 0 0 0 0 "-----")
		space=""

while true
	do
	
	       read -p "Text to convert: " tekst_inn
	       tekst_inn_ARRAY=(`echo $tekst_inn | tr " " "\n"`) #Hva er tr? Hvorfor \n?
		
	       for as in ${tekst_inn_ARRAY[@]} #Hvordan kunne jeg ha ordna det sånn at $as kunne vært et helt array?
					do 
  					eval 'morse0="${'"$as[0]"'}"' #Jeg må lære hvorfor dette funker...
  					eval 'morse1="${'"$as[1]"'}"'
  					eval 'morse2="${'"$as[2]"'}"'
					eval 'morse3="${'"$as[3]"'}"'
					eval 'morse4="${'"$as[4]"'}"'
					eval 'morse5="${'"$as[5]"'}"'
					eval 'morse6="${'"$as[6]"'}"'
					eval 'morse7="${'"$as[7]"'}"'
					eval 'morse8="${'"$as[8]"'}"'

						echo "$as $morse8"
						
						beep -r $morse0 -D $letter_part_pause -f 600 -l $morse1 2 > /dev/null #Kjører første gruppe
						beep -r $morse2 -D $letter_part_pause -f 600 -l $morse3 2 > /dev/null #Kjører andre gruppe
						beep -r $morse4 -D $letter_part_pause -f 600 -l $morse5 2 > /dev/null #Kjører tredje gruppe
						beep -r $morse6 -D $letter_part_pause -f 600 -l $morse7 2 > /dev/null #Kjører fjerde gruppe
						sleep $letter_pause
						
		done
done

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.
Server: bleh

Debian Logo