Python Forum
azure TTS from text files to mp3s
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
azure TTS from text files to mp3s
#2
Have you looked at response content print(response) to see if it's really is a binary format you get back?
Here a example found online you can try.
import requests
import json

# Replace with your Text to Speech subscription key
subscription_key = "YOUR_SUBSCRIPTION_KEY"

# Replace with the voice you want to use
voice = "en-US-Jessa24kRUS"

# Replace with the text you want to convert to speech
text = "Hello, this is an example of the Text to Speech API."

# Specify the language and format of the audio file
headers = {
    "Ocp-Apim-Subscription-Key": subscription_key,
    "Content-Type": "application/ssml+xml",
    "X-Microsoft-OutputFormat": "riff-24khz-16bit-mono-pcm",
    "User-Agent": "YOUR_RESOURCE_NAME"
}

# Create the SSML request
body = "<speak version='1.0' xml:lang='en-us'><voice xml:lang='en-us' xml:gender='Female' name='" + \
    voice + "'>" + text + "</voice></speak>"

# Make the request to the Text to Speech API
response = requests.post("https://YOUR_REGION.tts.speech.microsoft.com/cognitiveservices/v1", headers=headers, data=body)

# Save the generated audio file
with open("output.wav", "wb") as audio_file:
    audio_file.write(response.content)
print("The file has been saved to output.wav.")
Reply


Messages In This Thread
azure TTS from text files to mp3s - by mutantGOD - Jan-16-2023, 03:42 PM
RE: azure TTS from text files to mp3s - by snippsat - Jan-17-2023, 02:20 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Upload Files to Azure Storage Container phillyfa 6 773 Dec-22-2023, 06:11 AM
Last Post: Pedroski55
  Writing into 2 text files from the same function paul18fr 4 1,712 Jul-28-2022, 04:34 AM
Last Post: ndc85430
  Delete empty text files [SOLVED] AlphaInc 5 1,614 Jul-09-2022, 02:15 PM
Last Post: DeaD_EyE
  select files such as text file RolanRoll 2 1,200 Jun-25-2022, 08:07 PM
Last Post: RolanRoll
  Two text files, want to add a column value zxcv101 8 1,977 Jun-20-2022, 03:06 PM
Last Post: deanhystad
  Help Needed playing MP3s bill_z 2 1,045 Apr-13-2022, 01:44 PM
Last Post: bill_z
  select Eof extension files based on text list of filenames with if condition RolanRoll 1 1,555 Apr-04-2022, 09:29 PM
Last Post: Larz60+
  Separate text files and convert into csv marfer 6 2,937 Dec-10-2021, 12:09 PM
Last Post: marfer
  Sorting and Merging text-files [SOLVED] AlphaInc 10 4,972 Aug-20-2021, 05:42 PM
Last Post: snippsat
  Replace String in multiple text-files [SOLVED] AlphaInc 5 8,232 Aug-08-2021, 04:59 PM
Last Post: Axel_Erfurt

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020