tts-0 Basic introductory speech templating

Source: Internet
Author: User

The previous article introduced a simple example of TTS http://blog.csdn.net/u010176014/article/details/47326413

Let's talk a little bit more about how the speech reads the template. Like what

The template on the bus: * * To, open the door please be careful, get off please walk well.

Freshman enrollment system Template: Dan Gui fragrance A good tomorrow, the golden Autumn sent to greet the students Happo. * * Hello classmate, Welcome to * * University.

This article describes the most suitable for this case, the template is relatively fixed, only the individual is different. You can also change the configuration as needed to easily change the template.


I made a demo of the weather forecast.

The first step is to add a ResX file


A resource file is made up of XML and can be added to any resource, including binary. There are keys and value like a dictionary.

Then populate the content. The name is the key value, and the value write contains the parameter. For example, " good evening to the audience, it is Beijing time night [{0}], let's follow the city weather forecast." "The time in this can be assigned according to the specific circumstances." Take out the things that have changed.



The second step is to write a class that takes the text out of the resource.

Create a new resource class. The code inside is as follows.

Using system.text;using system.reflection;using system.resources;namespace ttsspeakdemo{public sealed class Resour Ce {#region Static part Private Const string resourcefilename = ".            Speaktemplt ";            static Resource Internalresource = new Resource ();            <summary>///Get File Resource management///</summary> public static Resource manager            {get {return internalresource;}            } #endregion #region Instance part ResourceManager rm = null; <summary>//Constructor//Get resource files///</summary> public Res Ource () {rm = new ResourceManager (this. GetType ().            Namespace + resourceFileName, assembly.getexecutingassembly ()); }///<summary>///Get the message from the assembly resource file for the specified key///</summary> PublIC string this[string key] {get {return RM.                GetString (key, System.Globalization.CultureInfo.CurrentUICulture);  }} #endregion}}

The third step is to draw an interface

I do it quite simply. Happy drink everyone continues to enrich.



Fourth Step Add event

<span style= "FONT-FAMILY:KAITI_GB2312;FONT-SIZE:18PX;" >using system;using system.collections.generic;using system.componentmodel;using System.Data;using System.drawing;using system.linq;using system.text;using system.windows.forms;using System.Media;using SpeechLib; namespace ttsspeakdemo{#region Voice reading text DEMO-2015-8-9-MDM//<summary>///Voice Read text DEMO-2015-8-7-MDM/// Lt;/summary> public partial class Speakdemo:form {public Speakdemo () {Initializecomp Onent ();//auto-generate, do not move}///<summary>//Pronunciation objects///</summary> public spvoice VO Ice = new SpVoice ();//This class is a core class that supports speech synthesis (TTS).        The TTS engine is invoked through the SpVoice object to enable read aloud functionality. Public Speechvoicespeakflags spflags = speechvoicespeakflags.svsfdefault;////<summary>//by keyword Voice Text resource content///</summary>//<param name= "key" ></param>//<returns></retu rns> private static string GettExtresourcebykey (string key) {return Resource.manager[key]. ToString ().        Trim (); private void Btnspeak_click (object sender, EventArgs e) {string beginword = Gettextreso Urcebykey ("Begin");//gets to the corresponding text string Baoding=gettextresourcebykey ("Baoding") according to the key value;//Ibid. String nowti me = DateTime.Now.ToString ("R");//Gets the time string Speakword = string. Format (Beginword, nowtime);            Greeting words and time string weather=txtweather.text;            String Air=txtair.text; String speakweather = String. Format (Baoding,weather, air);//put parameters into the template voice.            Speak (Speakword, spflags); Voice.        Speak (Speakweather, spflags); }} #endregion}</span>

So we can hear it ~ although simple but very practical oh ~

The demo will be transmitted to the network disk for you to see the effect directly. Http://yunpan.cn/cdrZjKsj4P7me Access Password e78c

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

tts-0 Basic introductory speech templating

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.