Text-to-speech Microsoft .NET SDK

The Voice RSS Text-to-Speech .NET SDK wraps Voice RSS Text-to-Speech API.

The Voice RSS Text-to-Speech .NET SDKs will help to make integration with our Text-to-Speech API faster and easer.

If you have any questions or suggestions please feel free to contact us via e-mail.

Documentation

To integrate an application with the Voice RSS Text-to-Speech .NET SDK it needs to add reference to the assembly VoiceRSS_TTS_SDK.DLL. The Voice RSS Text-to-Speech .NET SDK implements converting text-to-speech synchronously and asynchronously. The Voice RSS Text-to-Speech .NET SDK provides possibility to get speech in binary or Base64 string formats.

SDK specifications


Entity
Description
VoiceProvider
The SDK main class which provides text-to-speech converting functionality
IVoiceProvider
The interface which defines VoiceProvider class implementation
VoiceParameters
The class that contains voice parameters which defines text-to-speech converting parameters like text, language, and etc.
Languages
The enumeration which contains languages list for text-to-speech converting
Voices
The enumeration which contains voices list for text-to-speech converting
AudioCodec
The enumeration which contains audio codecs list for text-to-speech converting
AudioFormat
The enumeration which contains audio formats list for text-to-speech converting

Convert text-to-speech synchronously

The following example demonstrates synchronous converting text-to-speech as a binary array:

using System;
using System.IO;
using VoiceRSS_SDK;

namespace Examples
{
    class Program
    {
        static void Main(string[] args)
        {
            var apiKey = "<API key>";
            var isSSL = false;
            var text = "Hello, world!";
            var lang = Languages.English_UnitedStates;

            var voiceParams = new VoiceParameters(text, lang)
            {
                AudioCodec = AudioCodec.MP3,
                AudioFormat = AudioFormat.Format_44KHZ.AF_44khz_16bit_stereo,
                IsBase64 = false,
                IsSsml = false,
                SpeedRate = 0
            };

            var voiceProvider = new VoiceProvider(apiKey, isSSL);
            var voice = voiceProvider.Speech<byte[]>(voiceParams);

            var fileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "voice.mp3");
            File.WriteAllBytes(fileName, voice);
        }
    }
}

Convert text-to-speech asynchronously

The following example demonstrates asynchronous converting text-to-speech as a binary array based on event pattern:

using System;
using System.IO;
using VoiceRSS_SDK;

namespace Examples
{
    class Program
    {
        static void Main(string[] args)
        {
            var apiKey = "<API key>";
            var isSSL = false;
            var text = "Hello, world!";
            var lang = Languages.English_UnitedStates;

            var voiceParams = new VoiceParameters(text, lang)
            {
                AudioCodec = AudioCodec.MP3,
                AudioFormat = AudioFormat.Format_44KHZ.AF_44khz_16bit_stereo,
                IsBase64 = false,
                IsSsml = false,
                SpeedRate = 0
            };

            var voiceProvider = new VoiceProvider(apiKey, isSSL);

            voiceProvider.SpeechFailed += (Exception ex) =>
            {
                Console.WriteLine(ex.Message);
            };

            voiceProvider.SpeechReady += (object data) =>
            {
                var fileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "voice.mp3");
                File.WriteAllBytes(fileName, (byte[])data);
            };

            voiceProvider.SpeechAsync<byte[]>(voiceParams);
        }
    }
}

The following example demonstrates asynchronous converting text-to-speech as a binary array based on task pattern:

using System;
using System.IO;
using VoiceRSS_SDK;

namespace Examples
{
    class Program
    {
        static void Main(string[] args)
        {
            var apiKey = "<API key>";
            var isSSL = false;
            var text = "Hello, world!";
            var lang = Languages.English_UnitedStates;

            var voiceParams = new VoiceParameters(text, lang)
            {
                AudioCodec = AudioCodec.MP3,
                AudioFormat = AudioFormat.Format_44KHZ.AF_44khz_16bit_stereo,
                IsBase64 = false,
                IsSsml = false,
                SpeedRate = 0
            };

            var voiceProvider = new VoiceProvider(apiKey, isSSL);
            var voice = await voiceProvider.SpeechTaskAsync<byte[]>(voiceParams);

            var fileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "voice.mp3");
            File.WriteAllBytes(fileName, voice);
        }
    }
}

Convert text-to-speech as a Base64 string

The following example demonstrates asynchronous converting text-to-speech as a Base64 string in ASP.NET and plays it in an internet browser:

using System;
using VoiceRSS_SDK;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        var apiKey = "<API key>";
        var isSSL = false;
        var text = "Hello, world!";
        var lang = Languages.English_UnitedStates;

        var voiceParams = new VoiceParameters(text, lang)
        {
            AudioCodec = AudioCodec.MP3,
            AudioFormat = AudioFormat.Format_44KHZ.AF_44khz_16bit_stereo,
            IsBase64 = true,
            IsSsml = false,
            SpeedRate = 0
        };

        var voiceProvider = new VoiceProvider(apiKey, isSSL);
        var voice = voiceProvider.SpeechTaskAsync<string>(voiceParams);

        divPlayer.InnerHtml = string.Format("<audio src='{0}' autoplay='autoplay'></audio>", voice.Result);
    }
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <div id="divPlayer" runat="server"></div>
</body>
</html>