how to call azure service to generate text to voice
how to call api
https://centralindia.tts.speech.microsoft.com/cognitiveservices/v1 using
postman
ChatGPT
To call the API at https://centralindia.tts.speech.microsoft.com/cognitiveservices/v1 using Postman,
follow these steps:
Prerequisites
- Subscription
Key: You need a valid subscription key from Azure Cognitive Services.
- Authentication: Ensure you
have the necessary permissions and have your subscription key ready.
Steps to Make a POST Request
- Open Postman:
- Launch Postman
on your computer.
- Create a New
Request:
- Click on New and select Request.
- Set the Request
Type to POST:
- In the new
request window, set the HTTP method to POST.
- Enter the
Request URL:
- Enter https://centralindia.tts.speech.microsoft.com/cognitiveservices/v1 in the URL
field.
- Set Up Headers:
- Click on the Headers tab and add
the following headers:
- Ocp-Apim-Subscription-Key: Your
subscription key.
- Content-Type: application/ssml+xml
- X-Microsoft-OutputFormat: riff-24khz-16bit-mono-pcm (or any
other output format you need).
- Create the
Request Body:
- Click on the Body tab.
- Select the raw option.
- Ensure the
type is XML.
- Enter your
SSML (Speech Synthesis Markup Language) in the body. Here is an example
of what your SSML might look like:
xml
Copy code
<speak version='1.0' xml:lang='en-US'>
<voice xml:lang='en-US' xml:gender='Female' name='en-US-AriaNeural'>
Hello, this is a test.
</voice>
</speak>
- Send the
Request:
- Click the Send button to
make the request.
Example Postman Setup
Headers
Key |
Value |
Ocp-Apim-Subscription-Key |
your_subscription_key |
Content-Type |
application/ssml+xml |
X-Microsoft-OutputFormat |
riff-24khz-16bit-mono-pcm |
Body
xml
Copy code
<speak version='1.0' xml:lang='en-US'>
<voice xml:lang='en-US' xml:gender='Female' name='en-US-AriaNeural'>
Hello, this is a test.
</voice>
</speak>
Expected Response
- If successful,
the response will be the audio data in the specified format.
Troubleshooting
- 401
Unauthorized: Check your subscription key.
- 400 Bad Request: Check the
format of your SSML and headers.
- 500 Internal
Server Error: Try again later or check the Azure status.
By following these steps, you should be able to successfully call the
Text-to-Speech API using Postman.
4o
how to select speed
for above?
ChatGPT
To control the speaking speed in the SSML for the Text-to-Speech API, you
can use the <prosody> element within your SSML. The rate attribute of the <prosody> element allows you to adjust the
speaking speed.
Here's how you can modify your SSML to include the rate attribute to control the speed:
Example SSML with Speed Adjustment
xml
Copy code
<speak version='1.0' xml:lang='en-US'>
<voice xml:lang='en-US' xml:gender='Female' name='en-US-AriaNeural'>
<prosody rate="0.75">Hello, this is a test spoken
slowly.</prosody>
</voice>
</speak>
In this example, rate="0.75" means 75% of the default speed (i.e., slower). You can
adjust the rate attribute to different values to control the speed:
- rate="1.0" is the default
speed.
- rate="0.75" is 75% of the
default speed (slower).
- rate="1.25" is 125% of the
default speed (faster).
- You can also
use relative values like rate="slow", rate="medium", rate="fast".
Updated Postman Setup
Headers
Key |
Value |
Ocp-Apim-Subscription-Key |
your_subscription_key |
Content-Type |
application/ssml+xml |
X-Microsoft-OutputFormat |
riff-24khz-16bit-mono-pcm |
Body
xml
Copy code
<speak version='1.0' xml:lang='en-US'>
<voice xml:lang='en-US' xml:gender='Female' name='en-US-AriaNeural'>
<prosody rate="0.75">Hello, this is a test spoken
slowly.</prosody>
</voice>
</speak>
Steps in Postman
- Open Postman.
- Create a new
request and set the HTTP method to POST.
- Enter the
request URL: https://centralindia.tts.speech.microsoft.com/cognitiveservices/v1.
- Set the headers:
- Ocp-Apim-Subscription-Key: Your
subscription key.
- Content-Type: application/ssml+xml
- X-Microsoft-OutputFormat: riff-24khz-16bit-mono-pcm
- Set the body to raw and XML:
xml
Copy code
<speak version='1.0' xml:lang='en-US'>
<voice xml:lang='en-US' xml:gender='Female' name='en-US-AriaNeural'>
<prosody rate="0.75">Hello, this is a test spoken
slowly.</prosody>
</voice>
</speak>
- Send the
request.
This configuration will produce a speech output with the adjusted speed
based on the rate value you have set in the SSML.
4o
how to get free
subscription key from microsfot for above?
ChatGPT
To get a free subscription key for Microsoft's Text-to-Speech (TTS) API,
you need to sign up for an Azure account and create a Cognitive Services
resource. Microsoft offers a free tier that includes some free usage of the TTS
API. Here are the steps to obtain your free subscription key:
Steps to Get a Free Subscription Key
- Sign Up for an
Azure Account:
- Go to the Azure website.
- Click on the
"Start free" button to create a new Azure account.
- Follow the
on-screen instructions to set up your account. You'll need to provide
some basic information and a credit card for verification (no charges
will be made for the free tier).
- Create a
Cognitive Services Resource:
- Once your
Azure account is set up, log in to the Azure Portal.
- In the Azure
Portal, click on the "Create a resource" button.
- In the search
bar, type "Cognitive Services" and select it from the list.
- Click on the
"Create" button.
- Configure the
Cognitive Services Resource:
- Subscription: Select your
Azure subscription.
- Resource Group: Create a new
resource group or select an existing one.
- Region: Choose the
region closest to you (ensure it's the same as where you intend to use
the service, e.g., Central India).
- Name: Give your
Cognitive Services resource a unique name.
- Pricing Tier: Select the
free tier (F0) if available. This tier provides some free usage each
month.
- Review +
Create: Review your settings and click on the
"Create" button.
- Get Your
Subscription Key:
- After the
resource is created, navigate to it in the Azure Portal.
- Under the
"Keys and Endpoint" section, you will find two keys. You can
use either key for your API requests.
- Copy one of
the subscription keys.
Using the Subscription Key in Postman
Now that you have your subscription key, you can use it in Postman as
described in the previous steps:
- Open Postman.
- Create a new
request and set the HTTP method to POST.
- Enter the
request URL: https://centralindia.tts.speech.microsoft.com/cognitiveservices/v1.
- Set the headers:
- Ocp-Apim-Subscription-Key: Your
subscription key (copied from Azure).
- Content-Type: application/ssml+xml
- X-Microsoft-OutputFormat: riff-24khz-16bit-mono-pcm
- Set the body to raw and XML:
xml
Copy code
<speak version='1.0' xml:lang='en-US'>
<voice xml:lang='en-US' xml:gender='Female' name='en-US-AriaNeural'>
<prosody rate="0.75">Hello, this is a test spoken
slowly.</prosody>
</voice>
</speak>
- Send the
request.
By following these steps, you can obtain a free subscription key and use
it to make requests to the Text-to-Speech API with Postman.
4o
output as mp3 ? for
the above request postman reqeust?
ChatGPT
To receive the output as an MP3 file from the Microsoft Text-to-Speech
API, you need to modify the X-Microsoft-OutputFormat header to specify an MP3 output
format. Here are the steps to achieve this using Postman:
Steps to Make a POST Request for MP3
Output
- Open Postman:
- Launch Postman
on your computer.
- Create a New
Request:
- Click on New and select Request.
- Set the Request
Type to POST:
- In the new
request window, set the HTTP method to POST.
- Enter the
Request URL:
- Enter https://centralindia.tts.speech.microsoft.com/cognitiveservices/v1 in the URL
field.
- Set Up Headers:
- Click on the Headers tab and add
the following headers:
- Ocp-Apim-Subscription-Key: Your
subscription key.
- Content-Type: application/ssml+xml
- X-Microsoft-OutputFormat: audio-16khz-128kbitrate-mono-mp3
- Create the
Request Body:
- Click on the Body tab.
- Select the raw option.
- Ensure the
type is XML.
- Enter your
SSML (Speech Synthesis Markup Language) in the body. Here is an example
of what your SSML might look like:
xml
Copy code
<speak version='1.0' xml:lang='en-US'>
<voice xml:lang='en-US' xml:gender='Female' name='en-US-AriaNeural'>
<prosody rate="0.75">Hello, this is a test spoken
slowly.</prosody>
</voice>
</speak>
- Send the
Request:
- Click the Send button to
make the request.
Example Postman Setup
Headers
Key |
Value |
Ocp-Apim-Subscription-Key |
your_subscription_key |
Content-Type |
application/ssml+xml |
X-Microsoft-OutputFormat |
audio-16khz-128kbitrate-mono-mp3 |
Body
xml
Copy code
<speak version='1.0' xml:lang='en-US'>
<voice xml:lang='en-US' xml:gender='Female' name='en-US-AriaNeural'>
<prosody rate="0.75">Hello, this is a test spoken
slowly.</prosody>
</voice>
</speak>
Expected Response
- If successful,
the response will be the audio data in MP3 format. You can save this data
to an MP3 file.
Saving the Response as an MP3 File
- Send the
Request: Click the Send button in Postman.
- Save the
Response:
- After
receiving the response, click on the Save Response button (an
icon that looks like a download button) in Postman.
- Choose a
location to save the file and save it with an .mp3 extension.
By following these steps, you should be able to receive and save the
Text-to-Speech output as an MP3 file using Postman.