Cloudflare Workers Script for Text-to-Speech with Microsoft Speech API
The provided code is a Cloudflare Workers script that handles incoming HTTP requests. It listens for the 'fetch' event and responds with the result of the handleRequest function.\n\nThe generateUUID function generates a unique identifier using a random number generator and the UUID format. This UUID is used as a custom voice connection ID in the DEFAULT_HEADERS object.\n\nThe DEFAULT_HEADERS object contains the default headers that are sent with each request to the Microsoft Speech API. These headers include the API URL, accept language, user agent, content type, and other necessary information.\n\nThe speechApi function is an asynchronous function that sends a POST request to the Microsoft Speech API with the provided SSML (Speech Synthesis Markup Language) and retrieves the audio output in the form of an array buffer.\n\nThe handleRequest function handles the incoming request based on the request path. If the path is '/', it fetches an HTML page and returns it as the response. If the path is '/audio', it retrieves the text, rate, pitch, voice, and voice style parameters from the query string, generates the SSML with the provided parameters, and sends a request to the Microsoft Speech API to get the audio output. The audio output is then returned as the response.\n\nIf the request path is neither '/' nor '/audio', it returns a default response with the 'page' content and additional headers.\n\nTo use this script, you need to deploy it as a Cloudflare Worker and configure the necessary API credentials and endpoints.
原文地址: https://www.cveoy.top/t/topic/qor1 著作权归作者所有。请勿转载和采集!