MorseSharp is a .NET library to encoding/decoding up to 8 languages including kurdish and generating audio morse.
Use nuget package manager to install MorseSharp.
Install-Package MorseSharp
You can decode/encode use MorseSharp just by instantiating TextMorseConverter
class and pass 'Language' enum to specify the language.
using MorseSharp;
TextMorseConverter converter = new TextMorseConverter(Language.English);
Calling ConvertTextToMorse method and pass the text to encode the morse:
using MorseSharp;
var morse = await converter.ConvertTextToMorse("Hello");
Calling asynchronous methods ConvertMorseToText
to decode the morse:
โ Words must be separated by spaces, words by ( / ), Letters by space " ".
using MorseSharp;
var sentence = await converter.ConvertMorseToText(".... ...");
- To generate audio first you need to instantiate
MorseAudioConverter
, there are five overloaded constructor To configure audio options such as language and characters speed, word speed ,frequency. this WinForm example demonstrate the purpose:
MorseAudioConverter is just optimized wrapper of jstoddard's CWLibrary Library.
using MorseSharp;
MorseAudioConverter converter = new(Language.English,25,20,600);
//Or for kurdish language
//MorseAudioConverter converter = new(Language.Kurdish,25,20,600);
- Bytes for the generated wav audio can be recived by calling
MorseAudioConverter
's asynchronousConvertMorseToAudio
method:
try
{
var morse = await converter.ConvertMorseToAudio("Hello Morse");
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
3.After getting the bytes you can stream the bytes and play the sound, this example use's SoundPlayer object to play the sound:
SoundPlayer player = new();
using(Stream stream = new MemoryStream(morse))
{
player.Stream = stream;
player.PlayAsync();
}
This piece of code encode and decode's the morse and then show it to the console:
using MorseSharp;
using MorseSharp.Converter;
TextMorseConverter Converter = new TextMorseConverter(Language.English);
string morse = string.Empty;
string text = string.Empty;
try
{
morse = await Converter.ConvertTextToMorse("Hello World");
text = await Converter.ConvertMorseToText(".... ..");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.WriteLine(morse);
Console.WriteLine(text);