Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using SAPI is there a way to enter pinyin for Chinese pronunciation?

The goal is to be able to pronounce something like wo3. System.Speech can handle Chinese characters, but is there a way to input pinyin directly? It seems from http://msdn.microsoft.com/en-us/library/ms720566(v=vs.85).aspx that I should be able to write out the pinyin like so

<PRON SYM="ni 3"/>

How do I use PRON SYM?

Update: Here are some web pages that discuss the issue but with no solution: - http://www.ms-news.net/f3012/problem-with-phonemes-and-chinese-tts-3031240.html

Update2 I am using System.Speech.Synthesizer in .NET. Perhaps this is the issue. I can see that entering it into the Speech Properties works fine:

enter image description here

If I do this from C#, it just reads the tag:

        var culture = CultureInfo.GetCultureInfo("zh-CN");
        var synth = new SpeechSynthesizer();
        var voices = synth.GetInstalledVoices(culture);

        if (voices.Count > 0)
        {
            synth.SelectVoice(voices[0].VoiceInfo.Name);
            synth.Speak("<pron sym=\"ni 3 hao 3 xiao 1\"/>");
        }
like image 858
tofutim Avatar asked Jun 14 '11 07:06

tofutim


1 Answers

I’ve made this example and it works fine, I don’t speak Chinese, so, I use auto translator to get the sample word.

Here is the design of the form:

enter image description here

And here is the code behind it; I get the phoneme from the Chinese Phonemes table.

using System;
using System.Windows.Forms;
using SpeechLib;

namespace SpeechDemo
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }


        private void Form1_Load(object sender, EventArgs e)
        {
            //get installed voices
            SpVoice voice = new SpVoice();
            foreach (var item in voice.GetVoices())
            {
                comboBox1.Items.Add(((ISpeechObjectToken)item).GetDescription());
            }
        }

        private void btnSpeakPhonems_Click(object sender, EventArgs e)
        {
            if (comboBox1.SelectedIndex > 0)
            {
                SpVoice voice = new SpVoice();
                voice.Voice = voice.GetVoices().Item(comboBox1.SelectedIndex);
                voice.Speak("<pron sym=\"ang 1 zang 1\">变脏</pron>", SpeechVoiceSpeakFlags.SVSFlagsAsync);

            }
        }
    }
}

Be sure to select (Microsoft Simplified Chinese) from the ComboBox before testing. If you don’t have it you can download the language package of the Microsoft Speech (SpeechSDK51LangPack.exe).

Edit:

in SpeechSynthesizer pron => phoneme and sym => ph . here is code works fine with SpeechSynthesizer :

private void button1_Click(object sender, EventArgs e)
{
    var cu = CultureInfo.GetCultureInfo("zh-CN");
    SpeechSynthesizer sp = new SpeechSynthesizer();
    var voices = sp.GetInstalledVoices(cu);
    sp.SelectVoice(voices[0].VoiceInfo.Name);
    string s = "<?xml version=\"1.0\"?> <speak version=\"1.0\" xml:lang=\"zh-CN\"><phoneme ph=\"ang 1 zang 1\">变</phoneme></speak>";
    sp.SpeakSsml(s);
}
like image 191
Issam Ali Avatar answered Oct 20 '22 00:10

Issam Ali