y de nuevo dll y el mercado - página 27

 
Alexsandr San:

aquí está la primera ejecución - cargado un archivo de texto con el texto ruso, algunos garabatos - pero tiene, guardar el archivo como .wav


copiado y pegado - obtuvo un archivo.wav en el archivo guardado en.wav.

Instantánea2

Archivos adjuntos:
 
Nikolai Karetnikov:

Bueno, esto es lo que pasa con Google

Dan el flujo en Base64. Pude convertirlo a mp3, pero no con LINEAR16.

LINEAR16 debe ser convertido a wav

El contenido de audio devuelto como LINEAR16 también contiene una cabecera WAV.
Method: text.synthesize  |  Cloud Text-to-Speech  |  Google Cloud
Method: text.synthesize  |  Cloud Text-to-Speech  |  Google Cloud
  • cloud.google.com
Synthesizes speech synchronously: receive results after all text input has been processed. Request body The request body contains data with the following structure: Fields Response body If successful, the response body contains data with the following structure: The message returned to the client by the method. Fields The audio data bytes...
 

pregunta a los expertos

Referirse a un servicio de Google en el código

En Google

1. una sola cabecera

2. la clave se pasa a través de la url

3. Controlamos el motor a través del archivo json.

En curl es así

curl -X POST -H "Content-Type: application/json" -d @request.json https://texttospeech.googleapis.com/v1/text:synthesize?key=AIzaSyCaLxPh84wXpLkT-zOE04MlvHj3JhLXU0w

request.json

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

curl obtiene la respuesta correcta



Ahora implemente esto con WebRequest


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
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);
  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)
        {
         //--- успешная загрузка
         PrintFormat("Файл успешно загружен, размер %d байт.",ArraySize(result));
         PrintFormat("Заголовки сервера: %s",result_headers);
         //--- сохраняем данные в файл
         int filehandle=FileOpen("result.wav",FILE_WRITE|FILE_BIN);
         if(filehandle!=INVALID_HANDLE)
           {
            //--- сохраняем содержимое массива result[] в файл
            FileWriteArray(filehandle,result,0,ArraySize(result));
            //--- закрываем файл
            FileClose(filehandle);
            PlaySound("\\Files\\test.mp3");
           }
         else
            Print("Ошибка в FileOpen. Код ошибки =",GetLastError());
        }
      else
         PrintFormat("Ошибка загрузки '%s', код %d",url,status);
     }
  }

Pero la respuesta es

2020.06.02 11:52:15.887 GoogleVoice (EURUSD,H1) Ошибка загрузки 'https://texttospeech.googleapis.com/v1/text:synthesize?key=AIzaSyCaLxPh84wXpLkT-zOE04MlvHj3JhLXU0w', код 400

como si el servidor no entendiera el array que se le envía en la variable json short

O bien estoy formando la matriz de forma incorrecta o algo más?

 
TheXpert:

LINEAR16 debe ser ondulable

¡debe! ) Y lo es.

La razón es.

si elimina los caracteres adicionales y "alimenta" la cadena limpia en Base64, obtendrá un archivo wav legible por PlaySound

 
Nikolai Karetnikov:

¡debe! ) Y citado.

La razón es.

si se eliminan los caracteres extra y se "alimenta" la cadena limpia a Base64, se obtiene un archivo wav PlaySound

es un json :-) de una manera agradable, usted debe obtener el valor de la clave audioContent

 
Nikolai Karetnikov:


Es posible que no puedas leerlo, así que

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

Es posible que no pueda leerlo, por lo que

Los archivos son diferentes

Laejecución del programa se interrumpe en la etapa de WebRequest, no llega a los archivos ))))

 
Maxim Kuznetsov:

es un json :-) de buena fe, necesitas obtener el valor de la clave audioContent

¡Oh, sí! ¡¡¡Gracias!!! )))

 
Nikolai Karetnikov:

Pero la respuesta es

como si el servidor no entendiera la variable json array short

O bien estoy formando la matriz de forma incorrecta o algo más?

El problema es el carácter nulo final.

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\"}}";
  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)
        {
         //--- успешная загрузка
         PrintFormat("Файл успешно загружен, размер %d байт.",ArraySize(result));
         PrintFormat("Заголовки сервера: %s",result_headers);
         //--- сохраняем данные в файл
         int filehandle=FileOpen("result.wav",FILE_WRITE|FILE_BIN);
         if(filehandle!=INVALID_HANDLE)
           {
            //--- сохраняем содержимое массива result[] в файл
            FileWriteArray(filehandle,result,0,ArraySize(result));
            //--- закрываем файл
            FileClose(filehandle);
            PlaySound("\\Files\\test.mp3");
           }
         else
            Print("Ошибка в FileOpen. Код ошибки =",GetLastError());
        }
      else
      {
         PrintFormat("Ошибка загрузки '%s', код %d",url,status);
         Print("result: ", CharArrayToString(result));
      }
     }
  }

y si obtiene un error de webrequest, es muy posible que haya información adicional en el parámetro de resultado.

Por ejemplo:

2020.06.02 12:29:27.935 google_speech (USDRUB,M30)      Ошибка загрузки 'https://texttospeech.googleapis.com/v1/text:synthesize?key=AIzaSyCaLxPh84wXpLkT-zOE04MlvHj3JhLXU0w', код 400
2020.06.02 12:29:27.935 google_speech (USDRUB,M30)      result: {
2020.06.02 12:29:27.935 google_speech (USDRUB,M30)        "error": {
2020.06.02 12:29:27.935 google_speech (USDRUB,M30)          "code": 400,
2020.06.02 12:29:27.935 google_speech (USDRUB,M30)          "message": "Invalid JSON payload received. Parsing terminated before end of input.\ncoding\":\"LINEAR16\"}}\u0000\n                    ^",
2020.06.02 12:29:27.935 google_speech (USDRUB,M30)          "status": "INVALID_ARGUMENT"
2020.06.02 12:29:27.935 google_speech (USDRUB,M30)        }
2020.06.02 12:29:27.935 google_speech (USDRUB,M30)      }
 
TheXpert:

el problema es el carácter nulo de terminación.

y si obtiene un error de webrequest, es muy posible que haya información adicional en el parámetro de resultado.

por ejemplo:

Gracias. )

Razón de la queja: