TTS-speech templated with zero basic knowledge, tts-entry speech Template

Source: Internet
Author: User

TTS-speech templated with zero basic knowledge, tts-entry speech Template

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

This article further describes how to read a template. For example

Template on the Bus: ** yes, please be careful when opening the door. Please get off the bus.

Template of the new student admission system: Dan guifang wishes a wonderful tomorrow, and the autumn is a great evening to welcome all the students. ** Hello! Welcome to ** University.

This article applies to this situation. The template is relatively fixed and only a few are different. You can also change the configuration as needed to easily change the template.


I made a weather forecast Demo.

Step 1 Add a resx File


A resource file is composed of XML and can be added to any resource, including binary. Keys and values are available like dictionaries.

Then fill in the content. The name is the Key value, and the value is included in the parameter. For example, "Good evening for audience friends, it's Beijing time evening [{0}]. Let's take a look at the city weather forecast ." The time here can be assigned as needed. Take out the changed items.



Step 2: Write a class to retrieve the text in the resource.

Create a Resource class. The Code is as follows.

Using System. text; using System. reflection; using System. resources; namespace TTSSpeakDemo {public sealed class Resource {# 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 // obtain the Resource file // </summary> public Resource () {rm = new ResourceManager (this. getType (). namespace + ResourceFileName, Assembly. getExecutingAssembly ());} /// <summary> /// obtain the message of the specified key from the program funding source file /// </summary> public string this [string key] {get {return rm. getString (key, System. globalization. cultureInfo. currentUICulture); }}# endregion }}

Step 3 draw an Interface

I am relatively simple. We will continue to enrich our experience ..



Step 4 Add events

<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 read text Demo-2015-8-9-MDM /// <summary> // speech read text Demo-2015-8-7-MDM /// </summary> public partial class Spe AkDemo: Form {public SpeakDemo () {InitializeComponent (); // automatically generated, do not move} // <summary> // pronunciation object // </summary> public SpVoice voice = new SpVoice (); // This class supports speech synthesis (TTS). Call the TTS engine through the SpVoice object to implement the reading function. Public SpeechVoiceSpeakFlags spFlags = SpeechVoiceSpeakFlags. SVSFDefault; ///// <summary> /// obtain the voice and text resource content using the keyword /// </summary> /// <param name = "key"> </param> /// <returns> </returns> private static string GetTextResourceByKey (string key) {return Resource. manager [key]. toString (). trim ();} private void btnSpeak_Click (object sender, EventArgs e) {string beginWord = GetTextResourceByKey ("Begin "); // obtain the corresponding text string baoDing = GetTextResourceByKey ("BaoDing") based on the key value; // same as string nowTime = DateTime. now. toString ("r"); // obtain the time string speakWord = string. format (beginWord, nowTime); // greeting and time string weather = txtWeather. text; string air = txtAir. text; string speakWeather = string. format (baoDing, weather, air); // put parameters in the template voice. speak (speakWord, spFlags); voice. speak (speakWeather, spFlags) ;}# endregion }</span>

So that we can hear it ~ Simple but practical ~

Upload the Demo to the online storage for you to see the effect. Http://yunpan.cn/cdrZjKsj4P7me access password e78c

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.