Text To Speech In Xamarin.Forms

Instruction

This article demonstrates how to create a Text to Speech application using C# and XAML in Xamarin.Forms.

Text To Speech - Basic Usage 

With this app, you can easily convert a text into speech (TTS). Just enter the text and the app speaks it for you.

Let’s start.

Step 1

Open Visual Studio and go to New Project >>Installed >> Visual C# >> Cross Platform.

Select Cross-Platform App, then give your project a name and location.

 

Step 2

After project creation, add the following Nuget Packages to your project.

• XXam.Plugins.TextToSpeech

Go to Solution Explorer and select your Solution. Right-click and select "Manage NuGet Packages for Solution".

 

Now, select the following Nuget Package and select your project to install it.


Step 3

Open Solution Explorer >> Project Name >> MainPage.xaml. Open the Design View of this page.

 
 
The code is given below.

 

Xaml Code

  1. <StackLayout>  
  2. <Entry x:Name="Enter"/>  
  3.   
  4. <Button Text="Speek" Clicked="Clicked Button"/>  
  5. </StackLayout>  

Step 4

Next, open Solution Explorer >> Project Name >> MainPage.xaml.cs. Then, click to replace the C# code.The code is given below.

 

The code is given below.

 

C# Code 
  1. using Plugin.TextToSpeech;  
  2. using System;  
  3. using Xamarin.Forms;  
  4.   
  5. namespace TextToSpeech  
  6. {  
  7.     public partial class MainPage : ContentPage  
  8.     {  
  9.         public MainPage()  
  10.         {  
  11.             InitializeComponent();  
  12.         }  
  13.         private void ClickedButton (object Sender, EventArgs args)  
  14.         {  
  15.             var text = Enter.Text;  
  16.   
  17.             CrossTextToSpeech.Current.Speak(text);  
  18.         }  
  19.     }  
  20. }  
Step 5

Press F5 or Build and Run the application.

Output

Run the given application and type some content in the textbox. Click "Speak" button. The app starts reading the given text.

 
Finally, we have successfully created a Xamarin.Forms Text To Speech app.

Up Next
    Ebook Download
    View all
    Learn
    View all