13

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\"/>");
        }
Makoto
  • 104,088
  • 27
  • 192
  • 230
tofutim
  • 22,664
  • 20
  • 87
  • 148

3 Answers3

5

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);
}
Issam Ali
  • 1,703
  • 3
  • 15
  • 35
  • Aha, I was using System.Speech.Synthesizer. – tofutim Jun 22 '11 at 17:11
  • Is this doable from System.Speech.Synthesizer? – tofutim Jun 22 '11 at 17:18
  • SpeechSynthesizer is kind of wrapper to SAPI COM library, and it seems it has problem with custom pronunciation. You should try using SpeakAsync with PromptBuilder parameter. Create new PromptBuilder and use AppendTextWithPronunciation. I’ve test it. It works with English culture but not with Chinese.... sorry for delay we have bad internet here :( – Issam Ali Jun 22 '11 at 18:12
  • PS, if SpeechSynthesizer is just a wrapper why not using the original library it works like charm ;) – Issam Ali Jun 22 '11 at 18:16
  • it seems there are some syntax changes in the xml used by SpeechSynthesizer . new code added to the answer works fine with SpeechSynthesizer. hope this will solve the problem. – Issam Ali Jun 22 '11 at 18:49
  • There is a bad barking sound at the beginning of ang 1 - wonder if that can be sorted out – tofutim Aug 21 '15 at 21:03
0

Have you tried with:

<PRON SYM="ni 3"> sometext</PRON>

?

Also you may want to check here.

CristiC
  • 22,068
  • 12
  • 57
  • 89
  • Yes, I get a TargetInvocationException. If you have a working sample of how to use it, that would be great! I was never ever able to make heads or tails from the docs. – tofutim Jun 21 '11 at 20:32
0

I think your example just needs a slight modification....

if (voices.Count > 0)        
{
     synth.SelectVoice(voices[0].VoiceInfo.Name);
     PromptBuilder pb = new PromptBuilder();
     pb.AppendSsml("<pron sym=\"ni 3 hao 3 xiao 1\"/>");
     synth.Speak(pb);
}
therealmitchconnors
  • 2,732
  • 1
  • 18
  • 36