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

3

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\"/>");
        }
Mcnamara answered 14/6, 2011 at 7:0 Comment(1)
Is there an inner-exception? If so, what is it?Chairborne
F
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);
}
Fifth answered 22/6, 2011 at 17:6 Comment(6)
Aha, I was using System.Speech.Synthesizer.Mcnamara
Is this doable from System.Speech.Synthesizer?Mcnamara
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 :(Fifth
PS, if SpeechSynthesizer is just a wrapper why not using the original library it works like charm ;)Fifth
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.Fifth
There is a bad barking sound at the beginning of ang 1 - wonder if that can be sorted outMcnamara
V
0

Have you tried with:

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

?

Also you may want to check here.

Vinous answered 21/6, 2011 at 18:9 Comment(1)
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.Mcnamara
P
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);
}
Provincialism answered 22/6, 2011 at 18:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.