<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Nuduja Mapa</title>
    <description>The latest articles on Forem by Nuduja Mapa (@nuduja).</description>
    <link>https://forem.com/nuduja</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F821158%2F964dcd37-0e9c-4633-bff6-565ee395ca9e.png</url>
      <title>Forem: Nuduja Mapa</title>
      <link>https://forem.com/nuduja</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/nuduja"/>
    <language>en</language>
    <item>
      <title>Azure Text To Speech with Javascript</title>
      <dc:creator>Nuduja Mapa</dc:creator>
      <pubDate>Thu, 04 Aug 2022 13:17:31 +0000</pubDate>
      <link>https://forem.com/nuduja/azure-text-to-speech-with-javascript-259</link>
      <guid>https://forem.com/nuduja/azure-text-to-speech-with-javascript-259</guid>
      <description>&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;Azure subscription - Create one for free&lt;br&gt;
Create a Speech resource in the Azure portal.&lt;br&gt;
Get the resource key and region. After your Speech resource is deployed, select Go to resource to view and manage keys. For more information about Cognitive Services resources, see Get the keys for your resource.&lt;/p&gt;

&lt;h2&gt;
  
  
  Azure Text To Speech Function in the Azure Portal
&lt;/h2&gt;

&lt;p&gt;The status of the created resource can be checked by navigating to the overview tab&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F722gzc7i2mo82t31pb8r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F722gzc7i2mo82t31pb8r.png" alt="Resource Overview"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The keys and the endpoints of the resource can be found by navigating to "Keys and Endpoints" under the Resource Management Tab.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F134s87iibci7p9bsiw6o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F134s87iibci7p9bsiw6o.png" alt="Key and Endpoints"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That covers the Azure Text to speech configuration in the Azure Portal.&lt;/p&gt;

&lt;h2&gt;
  
  
  Coding
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Create a file named “SpeechSynthesis.js”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Install the Speech SDK for JavaScript by opening the command prompt and running the code.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;npm install microsoft-cognitiveservices-speech-sdk&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Copy the following code into “SpeechSynthesis.js”&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

(function() {

“use strict”;

//Configure Azure Cognitive service

var sdk = require(“microsoft-cognitiveservices-speech-sdk”);

var readline = require(“readline”);

var key = “YourSubscriptionKey”;

var region = “YourServiceRegion”;

var audioFile = “YourAudioFile.wav”;

const speechConfig = sdk.SpeechConfig.fromSubscription(key, region);

const audioConfig = sdk.AudioConfig.fromAudioFileOutput(audioFile);

// The language of the voice that speaks.

speechConfig.speechSynthesisVoiceName = “en-US-JennyNeural”;

// Create the speech synthesizer.

var synthesizer = new sdk.SpeechSynthesizer(speechConfig, audioConfig);

var rl = readline.createInterface({

input: process.stdin,

output: process.stdout

});

rl.question(“Enter some text that you want to speak &amp;gt;\n&amp;gt; “, function (text) {

rl.close();

// Start the synthesizer and wait for a result.

synthesizer.speakTextAsync(text,

function (result) {

if (result.reason === sdk.ResultReason.SynthesizingAudioCompleted) {

console.log(“synthesis finished.”);

} else {

console.error(“Speech synthesis canceled, “ + result.errorDetails +

“\nDid you set the speech resource key and region values?”);

}

synthesizer.close();

synthesizer = null;

},

function (err) {

console.trace(“err — “ + err);

synthesizer.close();

synthesizer = null;

});

console.log(“Now synthesizing to: “ + audioFile);

});

}());



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;Change “YourSubscriptionKey”, “YourServiceRegion” and “YourAudioFile” with the Speech resource key, Speech resource region, and desired output filename respectively.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In order to run your new console application, execute the code;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;node SpeechSynthesis.js&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo2i5h1nyllexdozdk3k5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo2i5h1nyllexdozdk3k5.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>azure</category>
      <category>texttospeech</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Azure Text To Speech with Postman</title>
      <dc:creator>Nuduja Mapa</dc:creator>
      <pubDate>Thu, 04 Aug 2022 13:11:54 +0000</pubDate>
      <link>https://forem.com/nuduja/azure-text-to-speech-with-postman-1g4c</link>
      <guid>https://forem.com/nuduja/azure-text-to-speech-with-postman-1g4c</guid>
      <description>&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;Azure subscription - Create one for free&lt;br&gt;
Create a Speech resource in the Azure portal.&lt;br&gt;
Get the resource key and region. After your Speech resource is deployed, select Go to resource to view and manage keys. For more information about Cognitive Services resources, see Get the keys for your resource.&lt;/p&gt;
&lt;h2&gt;
  
  
  Azure Text To Speech Function in the Azure Portal
&lt;/h2&gt;

&lt;p&gt;The status of the created resource can be checked by navigating to the overview tab&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F722gzc7i2mo82t31pb8r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F722gzc7i2mo82t31pb8r.png" alt="Resource Overview"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The keys and the endpoints of the resource can be found by navigating to "Keys and Endpoints" under the Resource Management Tab.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F134s87iibci7p9bsiw6o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F134s87iibci7p9bsiw6o.png" alt="Key and Endpoints"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That covers the Azure Text to speech configuration in the Azure Portal.&lt;/p&gt;
&lt;h2&gt;
  
  
  Configuring Postman
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Set the Endpoint URL as the Request URL&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Set the Request URL Type to Post&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the Header section,&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Set the key as "Ocp-Apim-Subscription-Key" and the first key 
 as its value.&lt;/li&gt;
&lt;li&gt;Set the key as "Content-type" and its key as 
 "application/ssml+xml"&lt;/li&gt;
&lt;li&gt;Set the key as "X-Microsoft-OutputFormat" and its key as the 
 desired type of audio file format and quality.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdcyt3wxiww3asolwu5r7.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdcyt3wxiww3asolwu5r7.jpg" alt="Example of the filled Header section"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;4.In the Body section, configure it to raw XML and copy the following code,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;speak version='1.0' xml:lang='en-US'&amp;gt;&amp;lt;voice xml:lang='en-US' xml:gender='Female'
name='en-US-JennyNeural'&amp;gt;
Hello, I am trying Azure Text To Speech
&amp;lt;/voice&amp;gt;&amp;lt;/speak&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F53jaw8wkqlyd709dmiwa.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F53jaw8wkqlyd709dmiwa.jpg" alt="Example Filled Body Section"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;5.Then click on the Send button to send the request.&lt;/p&gt;

&lt;p&gt;6.To save the audio file received as the response. Click on "Save Response" and then select "save to file". Select the desired location in the "Select path to save file" dialog box and click on "Save"&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7fpbtzwkzohnqrcavx4e.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7fpbtzwkzohnqrcavx4e.jpg" alt="Save response"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F85dttt8gbhx7m3kxic9e.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F85dttt8gbhx7m3kxic9e.jpg" alt="Save to file"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Simply add the text you need to be narrated in the given code. The Languages can be changed as provided by Azure Cognitive Services.&lt;/p&gt;

</description>
      <category>azure</category>
      <category>texttospeech</category>
      <category>postman</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
