and again dll and market - page 31

 
Andrei Trukhanovich:

my point is that it doesn't matter.

your code (almost) works for russian.)

attention span has fallen asleep, apparently ))

 
Реter Konow:

You're welcome!

By the way, I need to tell TC that this one:

A very strange entry. Why specify the size of the post array in such a strange way. TheStringToCharArray function sets the right size to the dynamic array itself.ArrayResize seems to be superfluous here.

This is exactly what I understand.

MQL5 Reference / Data Conversion / StringToCharArray

The terminal 0 will also be copied into the target array, and the size of the dynamic array can be increased as needed to fit the string size.

 
Nikolai Karetnikov:

this is exactly what is clear.

MQL5 Reference / Data Conversion / StringToCharArray

The terminal 0 will also be copied into the recipient array and the size of the dynamic array can be increased to fit the string size, if necessary.

I'm certainly not a coding pedant, but are you changing the size of the array by repeatedly calling the function that performs string-to-char conversion?)))

You could do that:

  int q = StringToCharArray(jsonbody,post,0,-1,CP_UTF8);
  ArrayResize(post, q - 1);

Otherwise, we are calling the conversion of the same string twice. Moreover, the second time cancels the first one.

 

Also, note the word "or" in the documentation:

[in] Number of array elements to copy. Defines the length of the result string. The default is -1, which means copying to the end of the array, or meeting the terminal 0. The terminal 0 will also be copied to the destination array, and the size of the dynamic array can be increased to match the string size if needed. If the size of the dynamic array is larger than the string length, the array size will not be reduced.

We don't know whether this terminal null is there or not, but we reduce the size of the array post, so we may lose the closing bracket if no terminal null is there.

It is worth checking the integrity of the char-converted string by reverse-conversion.

 
I did it! Said "one, two"))
 
#include <JAson.mqh>
void OnStart()
  {

   char    result[];
   char    post[];
   string  url="https://texttospeech.googleapis.com/v1/text:synthesize?key=AIzaSyCaLxPh84wXpLkT-zOE04MlvHj3JhLXU0w";
   string  headers;
   string  result_headers;
   int     status;
   
   
   string jsonbody;
   headers = "Content-Type: application/json";


  jsonbody = "{\"input\":{\"text\":\"one, two\"},\"voice\":{\"languageCode\":\"en-gb\",\"name\":\"en-GB-Wavenet-B\"},\"audioConfig\":{\"audioEncoding\":\"LINEAR16\"}}";  
  jsonbody = "{\"input\":{\"text\":\"раз, два, три, четыре, пять, вышел зайчик погулять\"},\"voice\":{\"languageCode\":\"ru-RU\",\"name\":\"ru-RU-Wavenet-B\"},\"audioConfig\":{\"audioEncoding\":\"LINEAR16\"}}";

 
   
  int q = StringToCharArray(jsonbody,post,0,-1,CP_UTF8);
  ArrayResize(post, q - 1);
  status=WebRequest("POST",url,headers,100000,post,result,result_headers);

   
   if(status==-1)
     {
      Print("Ошибка в WebRequest. Код ошибки  =",GetLastError());
      //---
      StringSetLength(url,StringFind(url,"/",8));
      MessageBox("Необходимо добавить адрес '"+url+"' в список разрешенных URL во вкладке 'Советники'","Ошибка",MB_ICONINFORMATION);
     }
   else
     {
      if(status==200)
        {
        CJAVal  CJasonResult;
        string lBase64String;
        char lBase64ResultArray[];
        char lBinaryDataArray[];
        char lkey[1];


        CJasonResult.Deserialize(result);
        lkey[0]=0;
        lBase64String = CJasonResult["audioContent"].ToStr();
        StringToCharArray(lBase64String,lBase64ResultArray,0,StringLen(lBase64String));
        CryptDecode(CRYPT_BASE64,lBase64ResultArray,lkey,lBinaryDataArray);
         //--- успешная загрузка
         PrintFormat("Файл успешно загружен, размер %d байт.",ArraySize(result));
         PrintFormat("Заголовки сервера: %s",result_headers);
         //--- сохраняем данные в файл
         int filehandle=FileOpen("result.wav",FILE_WRITE|FILE_BIN);
         if(filehandle!=INVALID_HANDLE)
           {
           
            //--- сохраняем содержимое массива result[] в файл
            FileWriteArray(filehandle,lBinaryDataArray,0,ArraySize(result));

            //--- закрываем файл
            FileClose(filehandle);
            PlaySound("\\Files\\result.wav");
           }
         else
            Print("Ошибка в FileOpen. Код ошибки =",GetLastError());
        }
      else
         PrintFormat("Ошибка загрузки '%s', код %d",url,status,result_headers);
     }
  }
 
One, two, three, four, five, the bunny went for a walk! ))))
 
TC, you did it. This is your success! Only a small mistake in the code was missed. I fixed it and it worked! ))))
 
Now, I suggest mastering STT (speach to text) to create voice control for the EA. The scheme is the same: connect to some cloud service (Google, for example) and use WebRequest to request a "live" text stream from the converted speech, which we then parse and send to the functionality. The result is very innovative.
 
Реter Konow:
One, two, three, four, five, the bunny went for a walk! ))))

Yes ! it works !!! cool

just need more of thisJasop.mqh

JP      0       05:05:49.668    22WebRequest (GBPNZD,H2)        Файл успешно загружен, размер 264457 байт.
MQ      0       05:05:49.668    22WebRequest (GBPNZD,H2)        Заголовки сервера: Content-Type: application/json; charset=UTF-8
DH      0       05:05:49.668    22WebRequest (GBPNZD,H2)        Vary: Origin
EN      0       05:05:49.668    22WebRequest (GBPNZD,H2)        Vary: X-Origin
OD      0       05:05:49.668    22WebRequest (GBPNZD,H2)        Vary: Referer
IO      0       05:05:49.668    22WebRequest (GBPNZD,H2)        Content-Encoding: gzip
ID      0       05:05:49.668    22WebRequest (GBPNZD,H2)        Date: Wed, 03 Jun 2020 02:05:48 GMT
MO      0       05:05:49.668    22WebRequest (GBPNZD,H2)        Server: ESF
GE      0       05:05:49.668    22WebRequest (GBPNZD,H2)        Cache-Control: private
EP      0       05:05:49.668    22WebRequest (GBPNZD,H2)        X-XSS-Protection: 0
MD      0       05:05:49.668    22WebRequest (GBPNZD,H2)        X-Frame-Options: SAMEORIGIN
CR      0       05:05:49.668    22WebRequest (GBPNZD,H2)        X-Content-Type-Options: nosniff
PP      0       05:05:49.668    22WebRequest (GBPNZD,H2)        Alt-Svc: h3-27=":443"; ma=2592000,h3-25=":443"; ma=2592000,h3-T050=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q049=":443"; ma=2592000,h3-Q048=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"
QL      0       05:05:49.668    22WebRequest (GBPNZD,H2)        Transfer-Encoding: chunked
LI      0       05:05:49.668    22WebRequest (GBPNZD,H2)
JSON Serialization and Deserialization (native MQL)
JSON Serialization and Deserialization (native MQL)
  • www.mql5.com
ForecastOscilator_HTF The ForecastOscilator indicator with the timeframe selection option available in the input parameters. Flat_HTF The Flat indicator with the timeframe selection option available in the input parameters. FX5_SelfAdjustingRSI_HTF The...
Files:
result.zip  126 kb
Reason: