and again dll and market - page 15

 
Реter Konow:
What does a 401 error mean?

enter "http 401" into Yandex and it tells you everything in detail.

 
Nikolai Karetnikov:

code result -"Webrequest4Voice(EURCHF,D1) Download error 'https://api.eu-gb.text-to-speech.watson.cloud.ibm.com/instances/9886a3ce-5734-455f-8f78-7a56381da686/v1/synthesize?text=TEST', code 401"

401 isserver requires authentication

Take a query emulator (e.g. postman) and make a normal request there and then transfer it to mql.

Or as Maxim wrote above
 
Maxim Kuznetsov:

enter "http 401" into Yandex and it tells you everything in detail.

Who said there was an http error? The TC didn't explain and I have to look it up?)))
 

https://example-files.online-convert.com/audio/wav/example.wav

downloaded from here without any problems

Snapshot3

and plays the sound

 
Alexsandr San:

https://example-files.online-convert.com/audio/wav/example.wav

downloaded from here without any problems


How playable is the downloaded file if it is written to the Files folder immediately after downloading? Add a couple of lines to the code there and you can check.
 
Реter Konow:
And how playable is the downloaded file if PlaySound plays it immediately into the Files folder after downloading it? Add a couple of lines to the code and you can test it.

so it goes straight to theFiles folder andeverything works sound

------------------------------------------------------------------

that's how I did it.

♪ it downloads and plays right away ♪

         int filehandle=FileOpen("example.wav",FILE_WRITE|FILE_BIN);
         if(filehandle!=INVALID_HANDLE)
           {
            //--- сохраняем содержимое массива result[] в файл
            FileWriteArray(filehandle,result,0,ArraySize(result));
            //--- закрываем файл
            FileClose(filehandle);
            Sleep(1*1000);
            PlaySound("\\Files\\example.wav");
           }
 
Alexsandr San:

so it goes straight to theFiles folder

Ok, is there a PlaySound call in the code after that? So that as soon as it's downloaded, it plays right away.
 
Maxim Kuznetsov:

To translate an HTTP request from curl options to WebRequest parameters, you have to:

1. in general, look at wikipedia to see how HTTP is structured

2. check in Curl documentation to see what options mean and why they are used

3. read the WebRequest help and see examples, even in this thread a lot

4. You should write code being aware of what you've done :-) what, why and why is it used.

You are obviously expecting all 4 points to be done for you. I understand it's weekend, time is short, and you have lots of ideas. It has to be quick.

But I still have to do it myself.

Maxim, ) Well, what's the point?

In curl there is only one parameter - "-u" is authorization or user, followed by apikey

In the WebRequest help file, you can figure out how to fill the resulting json array with yahoo finance response.

All the WebRequest examples in this thread are the one and only script in the help, which I posted the whole time )))).

Being aware of what has been done - it's hard to do without an example. Sites that commercially offer TTS have examples with .NET, Java, curl, mature programming languages, so to speak. They don't even have a clue about children like MQL.

So your post is important in theory, but insignificant in its usefulness.

Specifically, for me, for example, it's not clear where:

1) headers,

2) url or

3) somewhere else,

you need to specify the output to a wav file and I can't find examples, books that say this

 

Anyway, that's how it works.

//+------------------------------------------------------------------+
//|                                                   WebRequest.mq5 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   string cookie=NULL,headers;
   char   post[],result[];
   char cost_char_data[];
   string  result_headers;

   headers = "-u apikey:GR1bb3zVMs9fcNKL6pA9-5zj9ptWliCu6eh9oupUnpZB --output hello_world.wav";
   string url="https://example-files.online-convert.com/audio/wav/example.wav";
   ResetLastError();
   int res = WebRequest("GET",url,headers,1000,cost_char_data,result,result_headers);
   if(res==-1)
     {
      Print("Ошибка в WebRequest. Код ошибки  =",GetLastError());
      //--- возможно, URL отсутствует в списке, выводим сообщение о необходимости его добавления
      MessageBox("Необходимо добавить адрес '"+url+"' в список разрешенных URL во вкладке 'Советники'","Ошибка",MB_ICONINFORMATION);
     }
   else
     {
      if(res==200)
        {
         //--- успешная загрузка
         PrintFormat("Файл успешно загружен, размер %d байт.",ArraySize(result));
         //PrintFormat("Заголовки сервера: %s",headers);
         //--- сохраняем данные в файл
         int filehandle=FileOpen("example.wav",FILE_WRITE|FILE_BIN);
         if(filehandle!=INVALID_HANDLE)
           {
            //--- сохраняем содержимое массива result[] в файл
            FileWriteArray(filehandle,result,0,ArraySize(result));
            //--- закрываем файл
            FileClose(filehandle);
            Sleep(1*1000);
            PlaySound("\\Files\\example.wav");
           }
         else
            Print("Ошибка в FileOpen. Код ошибки =",GetLastError());
        }
      else
         PrintFormat("Ошибка загрузки '%s', код %d",url,res);
     }
  }
//+------------------------------------------------------------------+

only it's the wrong site.

Shot4

 
Alexsandr San:

so it goes straight to theFiles folder andeverything works sound

------------------------------------------------------------------

that's how I did it.

♪ it downloads and plays right away ♪

I see, so it's working. Now all that's left for TC to do is to sort out the webrequest and it's done.