当前位置:网站首页>Text to speech small software

Text to speech small software

2022-06-11 19:54:00 XiaOy's blog


The function of converting text into speech is very common , If you don't pursue voice individuality , It only needs a few lines of code to realize .

 Text to speech small software _microsoft

download

Code , Quote in the project

       
using System.Speech.Synthesis;
  • 1.


Four lines of code to achieve speaking :

       
using (SpeechSynthesizer voice = new SpeechSynthesizer())
{
voice.Rate = 1;
voice.Volume = 100;
voice.Speak(" Small y Design ");
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.


  Encapsulate the :

       
using System;
using System.Collections.Generic;
using System.Linq;
using System.Speech.Synthesis;
using System.Text;
using System.Threading.Tasks;

namespace SpeakHello
{
public class SoundHelper
{
/// <summary>
/// Default volume [0,100]
/// </summary>
public static int DefaultVolume = 100;
/// <summary>
/// Default sonic speed [-10,10]
/// </summary>
public static int DefaultRate = 1;

public static void Speak(string msg)
{
Speak(msg, DefaultRate, DefaultVolume);
}
/// <summary>
/// Broadcast voice
/// </summary>
/// <param name="msg"> Content </param>
/// <param name="rate"> The speed [-10,10]</param>
/// <param name="volume"> The volume [0,100]</param>
public static void Speak(string msg, int rate, int volume)
{
using (SpeechSynthesizer voice = new SpeechSynthesizer())
{
voice.Rate = rate;
voice.Volume = volume;
voice.Speak(msg);
}

}
}
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.


Expand the :

In addition to the default Anna voice , Other sounds can also be installed :Microsoft Mary,Microsoft Mike and Sample TTS Voice

       
speaker.SelectVoice("Microsoft Mike");
  • 1.


System.Speech and Microsoft.Speech Is different , And to avoid confusion , Only one of them should be selected .

about System.Speech


  1. Go to settings / Region and language / Add language
  2. From the language settings , Download voice

for example  Helen  be located en_US In the package . therefore , It should be done by adding English ( The United States ) Language to download other voice .

about Microsoft.Speech


  1. Download the voice from the link below
  2. Add pair      In the project Microsoft.Speech DLL


You can download it from the link below Microsoft Speech recognition and text to speech engine data files ;

be used for Microsoft Supported languages for speech recognition and text to speech engines  https://www.microsoft.com/en-us/download/details.aspx?id=27224

For more information :

Microsoft Voice programming guide

https://docs.microsoft.com/en-us/previous-versions/office/developer/speech-technologies/hh378466(v%3doffice.14)

SpeechSynthesizer.SelectVoice Method

https://docs.microsoft.com/en-us/previous-versions/office/developer/speech-technologies/dd167624(v%3Doffice.14)

System.Speech.Synthesis Namespace

https://docs.microsoft.com/en-us/dotnet/api/system.speech.synthesis?view=netframework-4.7.2

-----------------------------------------------------------------






原网站

版权声明
本文为[XiaOy's blog]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203011805570611.html