Jump to content

fix a script about unknown function name error


Recommended Posts

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

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

  • Developers

# 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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...