Я только что попытался использовать пользовательское произношение, используя лексикон PLS по ссылке http://msdn.microsoft.com/en-us/library/hh378403(v=office.14).aspx. Мой файл .pls выглядит следующим образом
Additional information
: Данные словаря недействительны или повреждены.
<?xml version="1.0" encoding="UTF-8"?>
<lexicon version="1.0"
xmlns="http://www.w3.org/2005/01/pronunciation-lexicon"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3.org/2005/01/pronunciation-lexicon
http://www.w3.org/TR/2007/CR-pronunciation-lexicon-20071212/pls.xsd"
alphabet="x-microsoft-ups" xml:lang="en-US">
<lexeme>
<grapheme> scale </grapheme>
<phoneme> S K A L E </phoneme>
</lexeme>
</lexicon>
and my grammar file is as pronunciation.grxml
<?xml version="1.0" encoding="UTF-8"?>
<grammar
version="1.0"
xml:lang="en-US"
root="colors"
sapi:alphabet="x-microsoft-ups"
xmlns:sapi="http://schemas.microsoft.com/Speech/2002/06/SRGSExtensions"
xmlns="http://www.w3.org/2001/06/grammar" tag-format="semantics/1.0" >
<lexicon uri="C:\Users\sony vaio\Documents\Visual Studio 2012\Projects\ConsoleApplication5\ConsoleApplication5\bin\Debug\Blue.pls" type="application/vdn.ms-sapi-lex"/>
<rule id="colors" scope="public">
<one-of>
<item> scale </item>
</one-of>
</rule>
</grammar>
и моя программа на С#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Xml;
using Microsoft.Speech;
using Microsoft.Speech.Recognition;
using Microsoft.Speech.Recognition.SrgsGrammar;
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
using (SpeechRecognitionEngine recognizer = new SpeechRecognitionEngine(new System.Globalization.CultureInfo("en-US")))
{
String currDirPath = Environment.CurrentDirectory;
string xmlGrammar = currDirPath + "\\pronunciation.grxml";
string cfgGrammar = currDirPath + "\\pronunciation.cfg";
FileStream fs = new FileStream(cfgGrammar, FileMode.Create);
XmlReader reader = XmlReader.Create(xmlGrammar);
//compile the grammar *.grxml to *.cfg file.
SrgsGrammarCompiler.Compile(reader, (Stream)fs);
fs.Close();
Grammar g = new Grammar(cfgGrammar, "colors");
Console.WriteLine(currDirPath+cfgGrammar);
recognizer.LoadGrammarAsync(g);
// Add a handler for the speech recognized event.
recognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);
// Configure the input to the speech recognizer.
recognizer.SetInputToDefaultAudioDevice();
// Start asynchronous, continuous speech recognition.
recognizer.RecognizeAsync(RecognizeMode.Multiple);
// Keep the console window open.
while (true)
{
Console.ReadLine();
}
}
}
// speech recognised event handler
static void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
string lines = e.Result.Text;
Console.WriteLine("Speak loudly");
Console.WriteLine("Recognized text: " + e.Result.Text);
Console.WriteLine("semantic value: " + e.Result.Semantics.Value.ToString());
}
}
но всякий раз, когда я пытаюсь скомпилировать его и использовать для распознавания «масштаба», он всегда показывает, что «Необработанное исключение типа «System.FormatException» произошло в Microsoft.Speech.dll. Дополнительная информация: данные лексикона недействительны или повреждены».
Хотя, когда используется встроенное произношение, оно работает, но произношение во внешней ссылке, похоже, не работает. Есть ли обходной путь? Любая помощь будет оценена по достоинству. Пожалуйста.