Undisputed 0 Posted January 15 Share Posted January 15 This code is looping through text files in the text folder, sending a POST request to the Azure Text to Speech service, and saving the generated speech as an MP3 file. On line 9, the _HttpRequest() function is used to send the text to the service, however it appears that this function has not been defined and is causing an error. To fix this, you should define the _HttpRequest() function, which is likely a custom function created for making HTTP requests. the line 9 throws an error # Declare variables Global Const $apiKey = "" Global Const $endpoint = "" Global Const $textFolder = "C:\Users\user\Desktop\text\" Global Const $audioFolder = "C:\Users\user\Desktop\audio\" Global Const $voice = "neutral" # Loop through text files in the text folder For $file in FileListToArray($textFolder, "*.txt") # Read the text from the file $text = FileRead($textFolder & $file) # Send a POST request to the Azure Text to Speech service $request = _HttpRequest("POST", $endpoint, "Content-Type: application/ssml+xml", "X-Microsoft-OutputFormat: audio-24khz-32kbitrate-mono-mp3", "Authorization: Bearer " & $apiKey, "User-Agent: AutoIt", "<speak version='1.0' xml:lang='en-US'><voice xml:lang='en-US' xml:gender='" & $voice & "'>" & $text & "</voice></speak>") # Check for errors If @error Then MsgBox(16, "Error", "An error occurred while sending the request to Azure Text to Speech service: " & @error) Exit EndIf # Save the generated speech as an MP3 file $audioFile = StringReplace($file, ".txt", ".mp3") FileSave($audioFolder & $audioFile, $request.Read) # Check for errors If @error Then MsgBox(16, "Error", "An error occurred while saving the audio file: " & @error) Exit EndIf Next Link to post Share on other sites
AutoBert 212 Posted January 15 Share Posted January 15 (edited) HTTP.au3 must be included. Edited January 15 by AutoBert Link to post Share on other sites
Undisputed 0 Posted January 15 Author Share Posted January 15 there is another problem with the & character where is says voice and text there is a & that doesnt pass $request = _HttpRequest("POST", $endpoint, "Content-Type: application/ssml+xml", "X-Microsoft-OutputFormat: audio-24khz-32kbitrate-mono-mp3", "Authorization: Bearer " & $apiKey, "User-Agent: AutoIt", "<speak version='1.0' xml:lang='en-US'><voice xml:lang='en-US' xml:gender='" & $voice & "'>" & $text & "</voice></speak>") Link to post Share on other sites
HurleyShanabarger 18 Posted January 15 Share Posted January 15 I always tought ; is the comment charater; was not aware that one could use # as well. Link to post Share on other sites
Developers Jos 2,811 Posted January 15 Developers Share Posted January 15 # is considered an directive line and when the word following the # isn't recognized, the line is ignored. This mechanic is used by tidy/autoit3wrapper and several other utilities. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to post Share on other sites
Undisputed 0 Posted January 16 Author Share Posted January 16 is there a workaround Link to post Share on other sites
Danp2 1,360 Posted January 16 Share Posted January 16 Check for errors following the FileRead. WebDriver UDF [GH&S] Latest version Wiki FAQs Link to post Share on other sites
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now