and again dll and market - page 28

 
TheXpert:

the problem is the terminating null character.

and if you get an error from webrequest, there may very well be extra information in the result parameter.

for example:

this downloads the file - only the format must be wrong, it doesn't play.

Snapshot3

 
Alexsandr San:

This is how it loads the file - but the format must be wrong, so it won't play.


If a proper .wav file was loaded, then it would play.

It plays like this.

Shot4

 

again I don't understand.

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
#include <JAson.mqh>
void OnStart()
  {

   char    post[],result[];
   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";
//---

// original json file
//{"input":{"text":"M"},"voice":{"languageCode":"en-gb"},"audioConfig":{"audioEncoding":"LINEAR16"}}
////

  jsonbody = "{\"input\":{\"text\":\"M\"},\"voice\":{\"languageCode\":\"en-gb\"},\"audioConfig\":{\"audioEncoding\":\"LINEAR16\"}}";
  StringToCharArray(jsonbody,post);
  ArrayResize(post, StringToCharArray(jsonbody,post) - 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[];


        CJasonResult.Deserialize(result);
        lBase64String = CJasonResult["audioContent"].ToStr();
        StringToCharArray(lBase64String,lBase64ResultArray,0,WHOLE_ARRAY,CP_ACP);
        
        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);
     }
  }


I get a Json stream, take only the needed string, put it into an array and decode the array.

Here's what I don't understand about decoding

CryptDecode(CRYPT_BASE64,lBase64ResultArray,lkey,lBinaryDataArray);

what kind of array [in] Key array.

The Help just says it should be there and that's all. What does it contain and what is its meaning?


 
Nikolai Karetnikov:

The reference says it has to be there and that's it. What does it contain and what is the point of it?

Make it null or fill it with zeros, you don't need it for base64

 
TheXpert:

make it zero-sized or null-sized, you don't need it for base64

so, the code has a zero size, but I added [1] and zeroed it


the array containing Base64 gets into CryptDecode and the resulting binary is empty

 
TC doesn't give up)))) That's good! Respect.
 
Nikolai Karetnikov:
StringToCharArray(lBase64String,lBase64ResultArray,0,StringLen(lBase64String));
 

However, this method is not safe and few people will want to use it.

This way, you can upload files and use some command to run things like .....

one script - upload, create a folder and copy to that folder.

Photo by

 

Well, as promised, I spoke to an IBM agent. Here is our simple and short dialogue:

You are now chatting with Lorenzo.

Today

Me on Jun 2, 3:31 PM

Hi, I have a question about Text To Speech service. Your free plan limit is 10 000 000 symbols per month, but Google free plan offers up to 4 000 000 symbols. So, can you explain to me this huge difference, or that i'm mistaken?

Hi!

There is a more suitable group who can help you. May I transfer you to this group so they can answer your question?

Ok!

I'll be right with you.

ok

Thanks for holding!

Yes, actually I am not supporting this product. Please contact to my colleague via email at Juan.Jose.Montero1@ibm.com

He will be happy to help you out or schedule a call!

Is that ok for you?

Well, I will write him, thanks a lot!

Thanks to you!

Is there anything else I can help you with today ?

Well, not really. Have a nice day !

//------------------------------------------------------------

I got sidetracked by the sales agent and the question had to do with the rates and limits of their service. Suggested I write a letter to someone called Jose Juan.

Productivity - США - Справка по MetaTrader 5
Productivity - США - Справка по MetaTrader 5
  • www.metatrader5.com
Индекс производительности труда показывает изменение объема выпущенной продукции, приходящегося на одного работника. Этот показатель полезен для предсказания инфляции и прироста объема производства. Если стоимость труда увеличивается соответственно увеличению производительности, и, кроме того, маловероятно увеличение производственных издержек...
 
TheXpert:
StringToCharArray(lBase64String,lBase64ResultArray,0,StringLen(lBase64String))

The last straw, so to speak.

Thank you!

That's a high five! )

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
#include <JAson.mqh>
void OnStart()
  {

   char    post[],result[];
   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";
//---

// original json file
//{"input":{"text":"M"},"voice":{"languageCode":"en-gb"},"audioConfig":{"audioEncoding":"LINEAR16"}}
////

  jsonbody = "{\"input\":{\"text\":\"MetaTrader 5 is a free application for traders allowing to perform technical analysis and trading operations in the Forex and exchange markets.\"},\"voice\":{\"languageCode\":\"en-gb\"},\"audioConfig\":{\"audioEncoding\":\"LINEAR16\"}}";
  StringToCharArray(jsonbody,post);
  ArrayResize(post, StringToCharArray(jsonbody,post) - 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);
     }
  }
Reason: