For the first time I come across this:

This:

https://tts.voicetech.yandex.net/generate?text=Наш%20текст%20гот+ов&format=mp3&lang=ru-RU&speaker=zahar&emotion=good&key=<API‑ключ> 

We need to convert this into this:

 https://tts.voicetech.yandex.net/generate?text=%D0%9D%D0%B0%D1%88%20%D1%82%D0%B5%D0%BA%D1%81%D1%82%20%D0%B3%D0%BE%D1%82+%D0%BE%D0%B2&format=mp3&lang=ru-RU&speaker=zahar&emotion=good&key=<API‑ключ> 

How does this happen? What does he translate Cyrillic to?

I read. I found out.

 URL url1 = new URL("https://tts.voicetech.yandex.net/generate?text=Наш%20текст%20гот+ов&format=mp3&lang=ru-RU&speaker=zahar&emotion=good&key=<API‑ключ>"); String s = url1.toString(); s = URLEncoder.encode(s, "utf-8"); URL url = new URL(s); 

does not work.

What's wrong?

In general, with this use goes like this:

It was :

 https://tts.voicetech.yandex.net/generate?text=Наш%20текст%20гот+ов&format=mp3&lang=ru-RU&speaker=zahar&emotion=good&key= 

It became:

 https%3A%2F%2Ftts.voicetech.yandex.net%2Fgenerate%3Ftext%3D%D0%9D%D0%B0%D1%88%2520%D1%82%D0%B5%D0%BA%D1%81%D1%82%2520%D0%B3%D0%BE%D1%82%2B%D0%BE%D0%B2%26format%3Dmp3%26lang%3Dru-RU%26speaker%3Dzahar%26emotion%3Dgood%26key% 

Conclusion :

it turns utf-8 into everything. How to turn only Russian letters?

  • All that comes after the text in Russian will constantly change with me, so how will this transformation be done? - Marat Zimnurov

1 answer 1

1. Create a new variable that is responsible for Russian letters.

2. The transformation method in utf-8 is performed on it.

3. We divide our URL in those places where Russian letters were used, and replace all Russian letters with a variable.

  String r ="Привет"; r = URLEncoder.encode(r, "utf-8"); System.out.println(r); URL url = new URL("https://tts.voicetech.yandex.net/generate?text="+r+"&format=mp3&lang=ru-RU&speaker=zahar&emotion=good&key="); 

As a result, part of the code with Russian letters successfully turns into:

  %D0%9F%D1%80%D0%B8%D0%B2%D0%B5%D1%82 

URL request is successfully processed.