1. Go to this page and download the library: Download ryanshay/sos library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ryanshay / sos example snippets
use SOS\Translator\Translator;
$translator = new Translator();
// Basic translation
$morse = $translator->textToMorse('Hello World');
echo $morse; // .... . .-.. .-.. --- / .-- --- .-. .-.. -..
$text = $translator->morseToText('... --- ...');
echo $text; // SOS
// IMPORTANT: Set output directory before generating any files
$translator->setOutputDirectory('/path/to/output');
$translator->setMaxFileSize(52428800); // Optional: 50MB default
use SOS\Translator\Translator;
use SOS\Translator\UnsupportedCharacterMode;
$translator = new Translator();
// Basic text to Morse
$morse = $translator->textToMorse('HELLO WORLD');
// Output: .... . .-.. .-.. --- / .-- --- .-. .-.. -..
// Morse to text
$text = $translator->morseToText('... --- ...');
// Output: SOS
// Single character lookup
$charMorse = $translator->getCharacterMorse('A');
// Output: .-
// Handle unsupported characters
$translator = new Translator(UnsupportedCharacterMode::SKIP);
$morse = $translator->textToMorse('Hello @ World'); // @ is skipped
$translator = new Translator(UnsupportedCharacterMode::REPLACE);
$morse = $translator->textToMorse('Hello @ World'); // @ replaced with ?
use SOS\Translator\Translator;
use SOS\Translator\AudioGenerator;
$translator = new Translator();
// REQUIRED: Set output directory first
$translator->setOutputDirectory('./output');
// Simple audio generation
$translator->generateAudioFile('SOS', 'sos.wav');
// Custom audio settings
$audioGen = new AudioGenerator();
$audioGen->setSpeed(20); // 20 words per minute
$audioGen->setFrequency(800); // 800 Hz tone
$audioGen->setVolume(0.7); // 70% volume
$audioGen->setSampleRate(22050); // Lower sample rate for smaller files
$translator->generateAudioFile('HELLO WORLD', 'custom.wav', $audioGen);
// Direct Morse to audio
$morseCode = '... --- ...';
$audioGen->generateWavFile($morseCode, 'morse.wav');
use SOS\Translator\Translator;
use SOS\Translator\VisualGenerator;
$translator = new Translator();
// REQUIRED: Set output directory first
$translator->setOutputDirectory('./output');
// Generate PNG image
$translator->generateVisualFile('SOS', 'sos.png');
// Generate SVG (scalable)
$translator->generateVisualFile('HELLO', 'hello.svg');
// Custom visual settings
$visualGen = new VisualGenerator();
$visualGen->setDotWidth(40); // Larger dots
$visualGen->setElementHeight(30); // Taller elements
$visualGen->setMaxWidth(600); // Narrower image
$visualGen->setColors(
[255, 255, 255], // White background
[0, 0, 0], // Black elements
[128, 128, 128] // Gray labels
);
$translator->generateVisualFile('MORSE CODE', 'custom.png', $visualGen);
use SOS\Translator\Translator;
$translator = new Translator();
// Inline terminal blinking
$translator->blinkInTerminal('SOS');
// Fullscreen terminal flashing
$translator->blinkInTerminal('EMERGENCY', [
'fullscreen' => true,
'speed' => 15, // 15 WPM
'repeats' => 3 // Repeat 3 times
]);
// Direct control with TerminalBlinker
use SOS\Translator\TerminalBlinker;
$blinker = new TerminalBlinker();
$blinker->setSpeed(20);
$blinker->setColors("\033[41m", "\033[40m"); // Red on/off
$blinker->blinkInline('... --- ...', 'SOS');
use SOS\Translator\Translator;
use SOS\Translator\BlinkPatternGenerator;
$translator = new Translator();
// REQUIRED: Set output directory first
$translator->setOutputDirectory('./output');
// Generate HTML with blinking animation
$translator->generateBlinkPattern('HELLO', 'hello.html');
// Custom HTML pattern
$blinkGen = new BlinkPatternGenerator();
$blinkGen->setSpeed(10); // Slow for learning
$blinkGen->setColors('#00FF00', '#000000'); // Green on black
$blinkGen->setLightSize(300); // Large light
$blinkGen->setIncludeControls(false); // Auto-play only
$translator->generateBlinkPattern('SOS', 'emergency.html', $blinkGen);
use SOS\Translator\Translator;
use SOS\Translator\GoveeController;
$controller = new GoveeController();
// Discover devices on the network
$devices = $controller->discoverDevices();
if (!empty($devices)) {
// Select the first device
$controller->selectDevice(0);
// Or select by IP address
// $controller->selectDeviceByIp('192.168.1.100');
$translator = new Translator();
$translator->blinkOnGoveeLight('SOS', $controller);
}
// Configure colors (RGB values)
$controller->setColors(
[255, 0, 0], // Red for "on" state
[0, 0, 0] // Off for "off" state
);
// Set speed
$controller->setSpeed(15); // 15 WPM for emergency
// Set brightness
$controller->setBrightness(100); // Maximum brightness
// Emergency signaling example
$controller->setColors([255, 0, 0]); // Red light
$controller->setBrightness(100);
$controller->setSpeed(15);
$translator->blinkOnGoveeLight('SOS HELP', $controller);
use SOS\Translator\Translator;
$translator = new Translator();
// REQUIRED: Set output directory first
$translator->setOutputDirectory('./output');
// Export as JSON
$translator->generateBlinkPattern('TEST', 'timings.json');
// Export as CSV
$translator->generateBlinkPattern('TEST', 'timings.csv');
// Get timing array
$timings = $translator->exportBlinkTimings('SOS', 'array');
// Returns: [
// ['state' => 'on', 'duration' => 60],
// ['state' => 'off', 'duration' => 60],
// ...
// ]
// Generate Arduino code
$arduinoCode = $translator->exportBlinkTimings('SOS', 'arduino');
// Returns complete Arduino sketch
use SOS\Translator\Translator;
use SOS\Translator\UnsupportedCharacterMode;
use SOS\Translator\Exceptions\InvalidCharacterException;
use SOS\Translator\Exceptions\InvalidMorseCodeException;
// Throw exceptions (default)
$translator = new Translator();
try {
$morse = $translator->textToMorse('Hello @');
} catch (InvalidCharacterException $e) {
echo "Invalid character: " . $e->getCharacter();
echo " at position: " . $e->getPosition();
}
// Skip invalid characters
$translator = new Translator(UnsupportedCharacterMode::SKIP);
$morse = $translator->textToMorse('Hello @ World');
// @ is supported, but if using an unsupported character:
// Skip mode will ignore it
// Replace mode will substitute it
// Replace invalid characters
$translator = new Translator(UnsupportedCharacterMode::REPLACE);
$translator->setReplacementCharacter('?');
$morse = $translator->textToMorse('Hello ~ World');
// ~ becomes ?, result
$translator = new Translator();
// REQUIRED before generating any files
$translator->setOutputDirectory('/path/to/safe/output');
// Optional: Set maximum file size (default 50MB)
$translator->setMaxFileSize(104857600); // 100MB
// Now you can generate files safely
$translator->generateAudioFile('HELLO', 'hello.wav');
$translator->generateVisualFile('HELLO', 'hello.png');
$translator->generateBlinkPattern('HELLO', 'hello.html');
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.