From 564d296679967ba2cf8c2d3d01894e8ebcfa8197 Mon Sep 17 00:00:00 2001 From: p6laris <71460146+p6laris@users.noreply.github.com> Date: Mon, 20 Nov 2023 06:17:13 +0300 Subject: [PATCH 1/3] Update README.md --- README.md | 148 +++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 102 insertions(+), 46 deletions(-) diff --git a/README.md b/README.md index 286dedc..10888d9 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ![Nuget](https://img.shields.io/nuget/dt/MorseSharp?logo=nuget) ![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/p6laris/MorseSharp) -MorseSharp is a .NET library to encoding/decoding **up to 9 languages** including kurdish and generating audio morse. +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](https://github.com/p6laris/MorseSharp/blob/master/MorseSharp.png?raw=true) @@ -28,90 +28,146 @@ Use nuget package manager to install [MorseSharp](https://www.nuget.org/packages Install-Package MorseSharp ``` ## Usage -### 1. Text -You can decode/encode use MorseSharp just by instantiating `TextMorseConverter` class and pass 'Language' enum to specify the language. +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. ```C# using MorseSharp; -TextMorseConverter converter = new TextMorseConverter(Language.English); + +var conv = Morse.GetConverter() + .ForLanguage(Language.English); ``` +### 1. Text +Once you've set the language via the `ForLanguage` method, you can decode/encode Morse code with a series of method calls. + #### Encoding -Calling ConvertTextToMorse method and pass the text to encode the morse: +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: ```C# using MorseSharp; -var morse = converter.ConvertTextToMorse("Hello"); + + var morse = Morse.GetConverter() + .ForLanguage(Language.English) + .ToMorse("Hi") + .Encode(); ``` +:warning: __WordNotPresentedException__ will be throw when a character in the input text does not have a corresponding Morse code representation. + #### Decoding -Calling method `ConvertMorseToText` to decode the morse: - > :exclamation: Words must be separated by spaces, words by ( / ), Letters by space " ". +to decode Morse code using the `Decode` method: + > :exclamation: ``Words must be separated by ( / ), Letters by space " ".`` ```C# using MorseSharp; -var sentence = converter.ConvertMorseToText(".... ..."); +var text = Morse.GetConverter() + .ForLanguage(Language.English) + .Decode(".... .."); + ``` +:warning: __SequenceNotFoundException__ when an invalid Morse code sequence is encountered, and the corresponding character cannot be found. + +### 2.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`: -### 2. Generating audio -1. 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](https://github.com/jstoddard)'s [CWLibrary](https://github.com/jstoddard/CWLibrary) Library. ```C# using MorseSharp; -MorseAudioConverter converter = new(Language.English,25,20,600); -//Or for kurdish language -//MorseAudioConverter converter = new(Language.Kurdish,25,20,600); - + Morse.GetConverter() + .ForLanguage(Language.English) + .ToMorse("Hello Morse") + .ToAudio() + .SetAudioOptions(25, 25, 600) + .GetBytes(out Span morse); ``` -2. Bytes for the generated wav audio can be recived by calling ``MorseAudioConverter``'s asynchronous ``ConvertMorseToAudio`` method: + +#### 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: ```C# -try -{ - var morse = await converter.ConvertMorseToAudio("Hello Morse"); -} -catch(Exception ex) -{ - MessageBox.Show(ex.Message); -} +using MorseSharp; + +Morse.GetConverter() + .ForLanguage(Language.English) + .ToAudio(".... ..") + .SetAudioOptions (25, 25, 600) + .GetBytes(out Span morse); + ``` -3.After getting the bytes you can stream the bytes and play the sound, this example use's SoundPlayer object to play the sound: +:warning: 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: + ```C# -SoundPlayer player = new(); -using(Stream stream = new MemoryStream(morse)) -{ - player.Stream = stream; - player.PlayAsync(); -} +using MorseSharp; + + //By Encoding it then blink the lights. +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 parameter`. + ## Example This piece of code encode and decode's the morse and then show it to the console: ```C# using MorseSharp; -using MorseSharp.Converter; - - -TextMorseConverter Converter = new TextMorseConverter(Language.English); -string morse = string.Empty; -string text = string.Empty; - try { - morse = Converter.ConvertTextToMorse("Hello World"); - text = Converter.ConvertMorseToText(".... .."); + //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) +catch(Exception ex) { Console.WriteLine(ex.Message); } - -Console.WriteLine(morse); -Console.WriteLine(text); ``` ## License From 71999c35e616c60bbaf2edc8357a4b3b381a1239 Mon Sep 17 00:00:00 2001 From: p6laris <71460146+p6laris@users.noreply.github.com> Date: Mon, 20 Nov 2023 06:51:29 +0300 Subject: [PATCH 2/3] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 10888d9..a4fac4c 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ var conv = Morse.GetConverter() .ForLanguage(Language.English); ``` -### 1. Text +## Text Once you've set the language via the `ForLanguage` method, you can decode/encode Morse code with a series of method calls. #### Encoding @@ -69,7 +69,7 @@ var text = Morse.GetConverter() ``` :warning: __SequenceNotFoundException__ when an invalid Morse code sequence is encountered, and the corresponding character cannot be found. -### 2.Audio +## Audio You have two options to generate audio: #### By Encoding The Text From c772a9a50a1ceab1ec265fd542d75c7648af2e77 Mon Sep 17 00:00:00 2001 From: p6laris <71460146+p6laris@users.noreply.github.com> Date: Fri, 1 Dec 2023 00:08:58 +0300 Subject: [PATCH 3/3] Update CODE_OF_CONDUCT.md --- CODE_OF_CONDUCT.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 3ee1633..f711456 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -1,5 +1,5 @@ # Code of Conduct -The [MorseSharp](https://github.com/p6laris/MorseSharp), have adopted the code of conduct defined by the [Contributor Covenant](http://contributor-covenant.org/) version 2.1, which can be found at[.NET Foundation](https://dotnetfoundation.org/about/code-of-conduct) +The [MorseSharp](https://github.com/p6laris/MorseSharp) has adopted the code of conduct defined by the [Contributor Covenant](http://contributor-covenant.org/) version 2.1, which can be found at[.NET Foundation](https://dotnetfoundation.org/about/code-of-conduct)