MorseSharp 4.1.0

dotnet add package MorseSharp --version 4.1.0
NuGet\Install-Package MorseSharp -Version 4.1.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MorseSharp" Version="4.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MorseSharp --version 4.1.0
#r "nuget: MorseSharp, 4.1.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install MorseSharp as a Cake Addin
#addin nuget:?package=MorseSharp&version=4.1.0

// Install MorseSharp as a Cake Tool
#tool nuget:?package=MorseSharp&version=4.1.0

MorseSharp

Nuget GitHub release (latest SemVer)

MorseSharp is a fast .NET library to encoding/decoding up to 10 languages including kurdish and generating audio , blinking lights for morse dash and dots.

alt text

Supported Languages

Language Enum Value
English Language.English
Kurdish Language.Kurdish
Kurdish Latin Language.KurdishLatin
Arabic Language.Arabic
Deutsch Language.Deutsch
Espanol Language.Espanol
Francais Language.Francais
Italiano Language.Italiano
Japanese Language.Japanese
Portugues Language.Portugues
Russian Language.Russian

Installation

Use nuget package manager to install MorseSharp.

Install-Package MorseSharp

Usage

Effortlessly decode/encode Morse code, generate audio, and control blinking lights using the fluent Morse class. Begin by obtaining a singleton instance through the GetConverter() method and specifying your desired language using the ForLanguage method and pass the Language enum to it.

using MorseSharp;

var conv = Morse.GetConverter()
     .ForLanguage(Language.English);

Text

Once you've set the language via the ForLanguage method, you can decode/encode Morse code with a series of method calls.

Encoding

Utilize the ToMorse method to encode your text into Morse code, and then call the Encode method to obtain the Morse code as a string:

using MorseSharp;

 var morse = Morse.GetConverter()
     .ForLanguage(Language.English)
     .ToMorse("Hi")
     .Encode();

⚠️ WordNotPresentedException will be throw when a character in the input text does not have a corresponding Morse code representation.

Decoding

to decode Morse code using the Decode method:

Words must be separated by ( / ), Letters by space " ".

using MorseSharp;

var text = Morse.GetConverter()
    .ForLanguage(Language.English)
    .Decode(".... ..");

⚠️ SequenceNotFoundException when an invalid Morse code sequence is encountered, and the corresponding character cannot be found.

Audio

You have two options to generate audio:

By Encoding The Text

Encode your text using ToMorse, and then proceed through the chain to generate audio for the encoded text. After encoding the text, use the ToAudio method, set the audio options with SetAudioOptions, and finally, retrieve audio bytes using GetBytes:

using MorseSharp;

 Morse.GetConverter()
     .ForLanguage(Language.English)
     .ToMorse("Hello Morse")
     .ToAudio()
     .SetAudioOptions(25, 25, 600)
     .GetBytes(out Span<byte> morse);
Manually

If you already have the encoded text as a string, skip the encoding step and pass the encoded text directly to the overloaded ToAudio method:

using MorseSharp;

Morse.GetConverter()
    .ForLanguage(Language.English)
    .ToAudio(".... ..")
    .SetAudioOptions (25, 25, 600)
    .GetBytes(out Span<byte> morse);

⚠️ The character speed must be greater than or equal to the word speed; otherwise, a SmallerCharSpeedException will be thrown.

Light

The class can also be able to blink lights to a specific morse. Just like the audio you have to options to blink lights either by Encoding it first or by set the dash and dots directly to the method and skip the encoding part:

using MorseSharp;

 //By Encoding it then blink the lights.
await Morse.GetConverter()
    .ForLanguage(Language.English)
    .ToMorse(null)
    .ToLight()
    .SetBlinkerOptions(25, 25)
    .DoBlinks((hasToBlink) => {
       //Do something
    });

//By directly pass the morse to method.
 await Morse.GetConverter()
     .ForLanguage(Language.English)
     .ToLight(".... ..")
     .SetBlinkerOptions(25, 25)
     .DoBlinks((hasToBlink) =>
     {
         if (hasToBlink)
             Console.BackgroundColor = ConsoleColor.White;
         else 
             Console.BackgroundColor = ConsoleColor.Black;
     });

You need to set the character speed and word speed using SetBlinkerOptions, then invoke async DoBlinks and subscribe to the Action<bool> parameter.

Example

This piece of code encode and decode's the morse and then show it to the console, also blinks the console background based on the light blink:

using MorseSharp;


try
{
    //Encoding
    var morse = Morse.GetConverter()
        .ForLanguage(Language.English)
        .ToMorse("Hi")
        .Encode();

    //Decoding
    var text = Morse.GetConverter()
        .ForLanguage(Language.English)
        .Decode(".... ..");

    //Light Blinking
    await Morse.GetConverter()
        .ForLanguage(Language.English)
        .ToLight(".... ..")
        .SetBlinkerOptions(25, 25)
        .DoBlinks((hasToBlink) =>
        {
            if (hasToBlink)
                Console.BackgroundColor = ConsoleColor.White;
            else 
                Console.BackgroundColor = ConsoleColor.Black;
        });

}
catch(Exception ex)
{
    Console.WriteLine(ex.Message);
}

License

MIT License

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
4.1.0 83 2/17/2024
4.0.1 96 2/9/2024
4.0.0 196 11/20/2023
3.2.0 116 10/3/2023
3.1.1 110 9/24/2023
3.1.0 113 9/23/2023
3.0.0 282 1/26/2023
2.0.2 392 10/13/2022
2.0.0 382 10/11/2022
1.3.1 399 10/8/2022
1.3.0 358 10/6/2022
1.2.2 370 10/4/2022
1.2.0 497 9/29/2022
1.0.1 370 9/29/2022
1.0.0 384 9/27/2022