Aller au contenu

TTS


frixo

Messages recommandés

Bonjour

 

petite question, j'aimerais bien avoir un moyen de faire parler un truc (genre mon googleHome, ou autre chose) pour faire un retour d'état de temps à autre.

 

Genre : Attention, le fer est allumé depuis 20min !

 

une idée ?

 

cdt

Lien vers le commentaire
Partager sur d’autres sites

  • 3 semaines après...

J'ai trouvé ce tuto concernant le TTS sur amazon écho...

J'ai suivi  ce tuto et ça fonctionne plutot bien.(délai d'une seconde entre la commande et le son émis).

 

Le lien : 

https://www.intelligentes-haus.de/2018/06/26/alexa-text-to-speech-tts-uber-fibaro-zentrale-nutzen/

 

En gros, il faut utiliser un script php (que j'ai herbergé sur mon nas syno) et ensuite créer une scène sur la hc2 qui appelle ce script.

 

C'est très paramétrable... ça passe par deux variables globales: la variable "pièce où se trouve l'écho" et la variable "le texte à énoncer".

 

On peut donc faire dire tout ce qu'on veut à Alexa...

 

Le point difficile pour moi a été de modifier légèrement le script php puisqu'il est rédigé en allemand qui renvoie au site amazon.de . Il faut simplement modifier et mettre amazon.fr à plusieurs endroits de ce script.

 

A bon entendeur..

  • Like 3
  • Thanks 1
Lien vers le commentaire
Partager sur d’autres sites

  • 2 mois après...
Le 19/07/2018 à 23:11, oldelvis a dit :

J'ai trouvé ce tuto concernant le TTS sur amazon écho...

J'ai suivi  ce tuto et ça fonctionne plutot bien.(délai d'une seconde entre la commande et le son émis).

 

Le lien : 

https://www.intelligentes-haus.de/2018/06/26/alexa-text-to-speech-tts-uber-fibaro-zentrale-nutzen/

 

En gros, il faut utiliser un script php (que j'ai herbergé sur mon nas syno) et ensuite créer une scène sur la hc2 qui appelle ce script.

 

C'est très paramétrable... ça passe par deux variables globales: la variable "pièce où se trouve l'écho" et la variable "le texte à énoncer".

 

On peut donc faire dire tout ce qu'on veut à Alexa...

 

Le point difficile pour moi a été de modifier légèrement le script php puisqu'il est rédigé en allemand qui renvoie au site amazon.de . Il faut simplement modifier et mettre amazon.fr à plusieurs endroits de ce script.

 

A bon entendeur..

Bonjour,

Vous serait il possible de partager votre script.

Merci

Lien vers le commentaire
Partager sur d’autres sites

  • 2 semaines après...
Le ‎06‎/‎10‎/‎2018 à 11:42, ymarchive a dit :

Bonjour,

Vous serait il possible de partager votre script.

Merci

Hello,

Voici la page php modifiée. A noter que comme indiqué dans le tutoriel, il faut générer le cookie qu'on sauvegarde sur le répertoire du site web pour l'authentification avec les services Amazon (à renouveller tous les 4 semaines en gros)

<!doctype html>
<html>
   <head>
      <meta charset="utf-8">
      <title>Alexa Text to Speech (TTS) by Lets Smart Home</title>
      <style>
         table, td, th { border: 1px solid black; }
      </style>
   </head>
   <body>
      <?php
         error_reporting(E_ALL);
         ini_set('display_errors', 1);

         //Variablen setzen
         $cookies="cookies.txt";
         $basic_url = 'https://alexa.amazon.fr';
		 $browser = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:60.0) Gecko/20100101 Firefox/60.0";
		 $user_lang = 'de,nl-BE;q=0.8,en-US;q=0.5,en;q=0.3,fr-FR,fr;q=0.5';


		echo "Your Browser is ".$_SERVER['HTTP_USER_AGENT']."<br>Your User Lang is: ".$_SERVER['HTTP_ACCEPT_LANGUAGE']."<br> When you have any trouble with this script open Alexa.php and replace this two data in the alexa.php -> user_lang and browser <br><br>";
		if(isset($_GET['device_name'])) {
			$device_name = $_GET['device_name'];
		}


		if(!file_exists($cookies)) die($cookies.' is not available in the order please attach and follow our instructions:');

		$cookie_file_ok = 0;
		if ( $check_cookie_file = file($cookies) ) {
			foreach($check_cookie_file as $check_cookie_file_data) {
				if(strpos($check_cookie_file_data,".amazon.fr")!==false) {
					$cookie_file_ok = 1;
				}
			}
		}
		if($cookie_file_ok == 0) die('Your '.$cookies.' does not seem to be okay Please check');

		if (!function_exists('curl_init')) {
   		 	echo "Curl is not enabled or installed on your web server at Synlogy: Webstation -> Php Settings -> Edit Php Profile -> choose the checkbox at extensions & curl";
		}


		function clear_string($str, $how = '_'){
			$search = array("ä", "ö", "ü", "ß", "Ä", "Ö",
                "Ü", "&", "é", "á", "ó",
                " :)", " :D", " :-)", " :P",
                " :O", " ;D", " ;)", " ^^",
                " :|", " :-/", ":)", ":D",
                ":-)", ":P", ":O", ";D", ";)",
                "^^", ":|", ":-/", "(", ")", "[", "]",
                "<", ">", "!", "\"", "§", "$", "%", "&",
                "/", "(", ")", "=", "?", "`", "´", "*", "'",
                "_", ":", ";", "²", "³", "{", "}",
                "\\", "~", "#", "+", ".", ",",
                "=", ":", "=)");

			$replace = array("ae", "oe", "ue", "ss", "Ae", "Oe",
                 "Ue", "und", "e", "a", "o", "", "",
                 "", "", "", "", "", "", "", "", "",
                 "", "", "", "", "", "", "", "", "",
                 "", "", "", "", "", "", "", "", "",
                 "", "", "", "", "", "", "", "", "",
                 "", "", "", "", "", "", "", "", "",
                 "", "", "", "", "", "", "", "", "", "");

			$str = str_replace($search, $replace, $str);
			$str = strtolower(preg_replace("/[^a-zA-Z0-9]+/", trim($how), $str));
			return $str;
}



         // Geräte lesen

         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL,''.$basic_url.'/api/devices-v2/device?cached=false');
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
         curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies);
         curl_setopt($ch, CURLOPT_COOKIEFILE, $cookies);
         curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
         $get_devices = curl_exec($ch);
         $get_devices_info = curl_getinfo($ch);
		 curl_close($ch);

         if($get_devices_info['http_code'] == 200) {

			if(strpos($get_devices,"Anmelden")!==false) {
				echo 'Your cookie information has expired or wrong please renew the cookies.txt If this does not help please delete in the browser all cookies then log in again and then you create a new cookies.txt and upload them! When you use Google Chrome and it isn`t work try it with Firefox ';
				echo '<br><br>';
				die(print_r($get_devices_info));


			}


          echo "<h1>The following devices are available in your Amazon account</h1>";
         echo "<table><tr><th>Name</th><th>serialNumber</th><th>deviceFamily</th><th>deviceType</th><th>deviceOwnerCustomerId</th><th>HTTP REQUEST URL</th></tr>";
         $user = json_decode($get_devices);

         	foreach($user->devices as $mydata) {
			if($mydata->deviceFamily == 'WHA') continue;
			if($mydata->deviceFamily == 'VOX') continue;
			if($mydata->deviceFamily == 'FIRE_TV') continue;
			if($mydata->deviceFamily == 'TABLET') continue;



				if(isset($device_name) && $device_name == clear_string($mydata->accountName)) {
		 			$serialNumber = $mydata->serialNumber;
		 			$deviceType = $mydata->deviceType;
		 			$deviceOwnerCustomerId = $mydata->deviceOwnerCustomerId;
				}

         ?>
      				<tr>
         				<td><?php echo clear_string($mydata->accountName);?></td>
         				<td><?php echo $mydata->serialNumber;?></td>
         				<td><?php echo $mydata->deviceFamily;?></td>
         				<td><?php echo $mydata->deviceType;?></td>
         				<td><?php echo $mydata->deviceOwnerCustomerId;?></td>
         				<td>http://<?php echo $_SERVER['HTTP_HOST'];?>/<?php echo $_SERVER['SCRIPT_NAME'];?>?device_name=<?php echo clear_string($mydata->accountName);?>&text_tts=here you can add your text</td>

      				</tr>
      	<?php




      			}

		echo "</table>";
		echo "<BR><BR>";
      } else {
			echo "an unknown error has occurred";
	  }


		if(isset($_GET['device_name'])) {
			$device_name = $_GET['device_name'];
		} else {
			die('No Device Name (device_name) selected!');
		}

		if(isset($_GET['text_tts'])) {
			$text_tts = $_GET['text_tts'];
		} else {
			die('No Text (text_tts) selected!');
		}

		if(strlen($text_tts) >= 1000) die('You really should not use more than 1000 characters in your text ');


		// TTS an amazon Senden
	$cookie_amazon_csrf = 0;
	if ( $get_cookies = file($cookies) ) {
		foreach($get_cookies as $data) {
			if(strpos($data,".amazon.fr")!==false) {
				if(strpos($data,"csrf")!==false) {
					$explode = explode('csrf',$data);
					$value = (int)str_replace('-','',$explode[1]);
				 	if($value != 0 ) {
						$cookie_amazon_csrf = $explode[1];
					}
				}
			}
		}
	}

	if($cookie_amazon_csrf == 0) die('Your "csrf" cookie is not available! The request can not be processed - your cookie.txt is wrong');

		$headers = [
			'Host: '.str_replace('https://','',$basic_url).'',
			'User-Agent: '.$browser.'',
			'Accept: */*',
			'Accept-Encoding: deflate, gzip',
			'DNT: 1',
			'Connection: keep-alive',
			'Content-Type: application/json; charset=UTF-8',
			'Accept-Language: '.$user_lang.'',
			'Referer: '.$basic_url.'/spa/index.html',
			'Origin: '.$basic_url.'',
			'csrf: '.(int)$cookie_amazon_csrf.'',
			'Cache-Control: no-cache'
		];

		$curl_tts = curl_init();
		curl_setopt($curl_tts, CURLOPT_URL,''.$basic_url.'/api/behaviors/preview');
		curl_setopt($curl_tts, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($curl_tts, CURLINFO_HEADER_OUT, 1);
		curl_setopt ($curl_tts, CURLOPT_POST, 1);
		curl_setopt($curl_tts, CURLOPT_POSTFIELDS, '{"behaviorId":"PREVIEW","sequenceJson":"{\"@type\":\"com.amazon.alexa.behaviors.model.Sequence\",\"startNode\":{\"@type\":\"com.amazon.alexa.behaviors.model.OpaquePayloadOperationNode\",\"type\":\"Alexa.Speak\",\"operationPayload\":{\"deviceType\":\"'.$deviceType.'\",\"deviceSerialNumber\":\"'.$serialNumber.'\",\"locale\":\"de-DE\",\"customerId\":\"'.$deviceOwnerCustomerId.'\",\"textToSpeak\":\"'.$text_tts.'\"}}}","status":"ENABLED"}');
		curl_setopt($curl_tts, CURLOPT_HTTPHEADER, $headers);
		curl_setopt($curl_tts, CURLOPT_COOKIEJAR, $cookies);
		curl_setopt($curl_tts, CURLOPT_COOKIEFILE, $cookies);
		curl_setopt($curl_tts, CURLOPT_FOLLOWLOCATION, true);

		$send_tts = curl_exec($curl_tts);
		$status_tts = curl_getinfo($curl_tts);

		if($status_tts['http_code'] == 200) {
			echo "<b>Your Text ".$text_tts." was sent to the following device: Name: ".$device_name.", serialNumber: ".$serialNumber.", deviceType: ".$deviceType.", deviceOwnerCustomerId: ".$deviceOwnerCustomerId."</b> ";
		} else {
			echo "Unfortunately, an error has leaked!";
			print_r($status_tts);
		}


?>
  </body>
</html>

 

Modifié par Riniack
  • Upvote 1
Lien vers le commentaire
Partager sur d’autres sites

Pour le cookie tu te sers de l'extension export cookie du navigateur chrome, tu vas sur la page d'accueil de ton compte amazon alexa, et là tu cliques sur l'extension cookie export pour générer un fichier texte que tu enregistres dans le dossier web comme indiqué. 

  • Like 1
Lien vers le commentaire
Partager sur d’autres sites

  • 3 semaines après...

Merci pour ces infos, cependant je rencontre un problème lorsque je lance le script PHP :

Your Browser is Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:63.0) Gecko/20100101 Firefox/63.0
Your User Lang is: fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3
When you have any trouble with this script open Alexa.php and replace this two data in the alexa.php -> user_lang and browser

Curl is not enabled or installed on your web server at Synlogy: Webstation -> Php Settings -> Edit Php Profile -> choose the checkbox at extensions & curl Fatal error: Uncaught Error: Call to undefined function curl_init() in /volume2/web/alexa_tts/alexa.php:77 Stack trace: #0 {main} thrown in /volume2/web/alexa_tts/alexa.php on line 77

Lien vers le commentaire
Partager sur d’autres sites

Le 26/06/2018 à 16:28, frixo a dit :

Bonjour

 

petite question, j'aimerais bien avoir un moyen de faire parler un truc (genre mon googleHome, ou autre chose) pour faire un retour d'état de temps à autre.

 

Genre : Attention, le fer est allumé depuis 20min !

 

une idée ?

 

cdt

regarde dans ma signature le tuto que je viens de faire

Lien vers le commentaire
Partager sur d’autres sites

  • 10 mois après...
  • 8 mois après...

Plop

 

Meme probleme ici  ..... ma liste est vide :(

 

 

alex.thumb.JPG.e042cab30bca74eb68a1d058ff076255.JPG

 

Voila les lignes dès 103.... foreach($user->devices as $mydata) {

          echo "<h1>The following devices are available in your Amazon account</h1>";
         echo "<table><tr><th>Name</th><th>serialNumber</th><th>deviceFamily</th><th>deviceType</th><th>deviceOwnerCustomerId</th><th>HTTP REQUEST URL</th></tr>";
         $user = json_decode($get_devices);

         	foreach($user->devices as $mydata) {
			if($mydata->deviceFamily == 'WHA') continue;
			if($mydata->deviceFamily == 'VOX') continue;
			if($mydata->deviceFamily == 'FIRE_TV') continue;
			if($mydata->deviceFamily == 'TABLET') continue;



				if(isset($device_name) && $device_name == clear_string($mydata->accountName)) {
		 			$serialNumber = $mydata->serialNumber;
		 			$deviceType = $mydata->deviceType;
		 			$deviceOwnerCustomerId = $mydata->deviceOwnerCustomerId;
				}

         ?>
      				<tr>
         				<td><?php echo clear_string($mydata->accountName);?></td>
         				<td><?php echo $mydata->serialNumber;?></td>
         				<td><?php echo $mydata->deviceFamily;?></td>
         				<td><?php echo $mydata->deviceType;?></td>
         				<td><?php echo $mydata->deviceOwnerCustomerId;?></td>
         				<td>http://<?php echo $_SERVER['HTTP_HOST'];?>/<?php echo $_SERVER['SCRIPT_NAME'];?>?device_name=<?php echo clear_string($mydata->accountName);?>&text_tts=here you can add your text</td>

      				</tr>
      	<?php

Une idée ?!

Modifié par Bloug
Lien vers le commentaire
Partager sur d’autres sites

  • 1 an après...
×
×
  • Créer...