Undisputed Posted January 15, 2023 Share Posted January 15, 2023 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 comment Share on other sites More sharing options...
AutoBert Posted January 15, 2023 Share Posted January 15, 2023 (edited) HTTP.au3 must be included. Edited January 15, 2023 by AutoBert Link to comment Share on other sites More sharing options...
Undisputed Posted January 15, 2023 Author Share Posted January 15, 2023 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 comment Share on other sites More sharing options...
HurleyShanabarger Posted January 15, 2023 Share Posted January 15, 2023 I always tought ; is the comment charater; was not aware that one could use # as well. Link to comment Share on other sites More sharing options...
Developers Jos Posted January 15, 2023 Developers Share Posted January 15, 2023 # 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 comment Share on other sites More sharing options...
Undisputed Posted January 16, 2023 Author Share Posted January 16, 2023 is there a workaround Link to comment Share on other sites More sharing options...
Danp2 Posted January 16, 2023 Share Posted January 16, 2023 Check for errors following the FileRead. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
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