How to convert Text to Speech
using C#
Download: | text-to-speech.zip |
This example demonstrates how to implement the text-to-speech feature in c#, which
is able to convert text messages to audio data. To fully understand this article, you
might have to study the
How to register to a SIP PBX chapter and the
How to ring a SIP extension chapters first.
To use this example, you need to have Ozeki VoIP SIP SDK installed,
and a reference to ozeki.dll should be added to your visual studio project.
What is Text-To-Speech used for during a SIP voice call? How does it work?
A text-to-speech (TTS) system converts normal language text into speech; other
systems render symbolic linguistic representation like phonetic transcriptions into speech.
Users can set text files to be read and sent into the call as speech, which is a very useful feature
for example at voicemails, IVRs (Interactive Voice Response), autodialers etc.
Text-to-Speech refers to the ability of computers to read text aloud. A TTS Engine converts written text to a phonemic representation, then converts the phonemic representation to waveforms that can be output as sound. TTS engines with different languages, dialects and specialized vocabularies are available through third-party publishers.
How to implement text-to-speech feature using C#?
Ozeki VoIP SIP SDK provides the c# TextToSpeech class for the purpose to create instances which
are able to convert text - which is (or it's path is) given as parameter - to voice data. This instance can
be attached to the call through the correct sender object, so the stream of voice data can
be be sent to the destination.
The example below introduces how to convert a text message into voice, and play that
on the default speaker.
Read and send text message as voice data example in C#
using System; using Ozeki.Media; using Ozeki.VoIP; namespace Text_To_Speech { class Program { static ISoftPhone softphone; // softphone object static IPhoneLine phoneLine; // phoneline object static IPhoneCall call; static MediaConnector connector; static PhoneCallAudioSender mediaSender; private static void Main(string[] args) { // Create a softphone object with RTP port range 5000-10000 softphone = SoftPhoneFactory.CreateSoftPhone(5000, 10000); // SIP account registration data, (supplied by your VoIP service provider) var registrationRequired = true; var userName = "858"; var displayName = "858"; var authenticationId = "858"; var registerPassword = "858"; var domainHost = "192.168.115.100"; var domainPort = 5060; var account = new SIPAccount(registrationRequired, displayName, userName, authenticationId, registerPassword, domainHost, domainPort); // Send SIP regitration request RegisterAccount(account); mediaSender = new PhoneCallAudioSender(); connector = new MediaConnector(); // Prevents the termination of the application Console.ReadLine(); } static void RegisterAccount(SIPAccount account) { try { phoneLine = softphone.CreatePhoneLine(account); phoneLine.RegistrationStateChanged += line_RegStateChanged; softphone.RegisterPhoneLine(phoneLine); } catch (Exception ex) { Console.WriteLine("Error during SIP registration: " + ex); } } static void line_RegStateChanged(object sender, RegistrationStateChangedArgs e) { if (e.State == RegState.NotRegistered || e.State == RegState.Error) Console.WriteLine("Registration failed!"); if (e.State == RegState.RegistrationSucceeded) { Console.WriteLine("Registration succeeded - Online!"); CreateCall(); } } private static void CreateCall() { var numberToDial = "853"; call = softphone.CreateCallObject(phoneLine, numberToDial); call.CallStateChanged += call_CallStateChanged; call.Start(); } static void SetupTextToSpeech() { var textToSpeech = new TextToSpeech(); mediaSender.AttachToCall(call); connector.Connect(textToSpeech, mediaSender); textToSpeech.AddAndStartText("Hello World!"); Console.WriteLine("The text is converted to speech and being played into the call."); } static void call_CallStateChanged(object sender, CallStateChangedArgs e) { Console.WriteLine("Call state: {0}.", e.State); if (e.State == CallState.Answered) SetupTextToSpeech(); } } }
Related Pages
More information
- How to build a softphone voip sip client
- Register to SIP PBX
- Voip softphone development
- How to encrypt voip sip calls with sip encryption
- How to encrypt voip sip calls with rtp encryption
- How to ring a sip extension csharp example for sip invite
- How to make a sip voice call using csharp
- Voip multiple phone lines
- How to send stream of voice data into call using csharp microphone
- How to receive voice from SIP voice call using csharp speaker
- How to make conference voice call using voip sip
- How to play an mp3 file into a voice call using csharp
- How to convert text to speech and play that into a call using csharp
- How to use Microsoft Speech Platform 11 for TTS and STT
- How to record voip sip voice call
- How to accept incoming call using csharp
- How to reject incoming call using csharp
- How to read Headset buttons using Bluetooth
- How to implement auto answer using csharp
- How to recognize incoming voice using speech to text conversion
- Voip forward call
- Voip blind transfer
- Voip attended transfer
- Voip do not disturb
- Voip call hold
- SIP Message Waiting Indication
- Voip DTMF signaling
- How to work with sip and sdp in voip sip calls
- How to work with rtp in voip sip calls
- How to make voip video calls in csharp
- Voip video codec
- Shows how to use SpeechToText Google API
- How to convert Text to Speech using C# and Google
- Azure Text-to-Speech