Skip to content

Instantly share code, notes, and snippets.

@thevickypedia
Created April 27, 2023 12:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thevickypedia/dfe0a0668a726267c7e1d99fc8bdfc8b to your computer and use it in GitHub Desktop.
Save thevickypedia/dfe0a0668a726267c7e1d99fc8bdfc8b to your computer and use it in GitHub Desktop.
Convert a python request to curl (without actually making a request)
SS_HEADERS = {
"Content-Type": "text/plain"
}
def check(response):
req = response.prepare()
command = "curl -X {method} \\\n -H {headers} \\\n -d '{data}' \\\n '{uri}'"
method = req.method
uri = req.url
data = req.body
headers = SS_HEADERS or req.headers
headers = ['"{0}: {1}"'.format(k, v) for k, v in headers.items()]
headers = "\\\n -H ".join(headers)
return command.format(method=method, headers=headers, data=data, uri=uri)
def checker():
import requests
response = requests.Request(
url=f"http://localhost:5002/api/tts",
headers=SS_HEADERS, params={"voice": "en-us_northern_english_male-glow_tts",
"vocoder": "medium"}, data="Welcome to the world of speech synthesis",
)
return response
if __name__ == '__main__':
print(check(checker()) + " \\\n --output temp.wav && open temp.wav")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment