PHP code example of badams / microsoft-translator

1. Go to this page and download the library: Download badams/microsoft-translator 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/ */

    

badams / microsoft-translator example snippets



use badams\MicrosoftTranslator\MicrosoftTranslator;

$clientId = 'YOUR_CLIENT_ID';
$clientSecret = 'YOUR_CLIENT_SECRET';

$translator = new MicrosoftTranslator();
$translator->setClient($clientId, $clientSecret);

// Translate a string of text from one language to another
$output = $translator->translate('Hello World!', $to = 'fr', $from = 'en');
echo $output; // Salut tout le monde!

// Detect the language of a string
$language = $translator->detect('Salut tout le monde!');
echo $language; // fr
echo $language->getEnglishName(); // French

//Returns a wave or mp3 stream of the passed-in text being spoken in the desired language.
$data = $translator->speak('Salut tout le monde!', 'fr');

header('Content-Type: audio/mp3');
echo base64_decode($data);