I am trying to play an audio using Google Text-To-Speech. Therefore I need to post a request to their endpoint with the Referer and the User-Agent properly set. This call should
You can't. It is impossible.
The specification requires that the browser abort the setRequestHeader
method if you try to set those headers.
If you need to set those headers then you'll need to make the request from your server and not your visitor's browser.
(That said, if you need to be deceptive about the user agent or referer then you are probably trying to use the service in a fashion that the owner of it does not want, so you should respect that and stop trying).
Also check the "Fetch forbidden header names".