AmoHayP
Newbie
Posts: 1
Joined: Mon May 06, 2013 9:56 am

sample of voice plugin

Wed May 15, 2013 9:58 am

2REVARN

You set the example plug-in, where it is necessary to write the text of the query (open door). Can you show sample code in C #, where I was able to self-edit options for voice query and response. Thanks.

User avatar
Leslie
Lead Software Architect
Posts: 377
Joined: Fri Sep 14, 2012 12:20 pm
Contact: Website

Re: sample of voice plugin

Sat May 25, 2013 2:00 am

CSharp Code

using SynModule;
using SynModule.Terms;

public class Automation : SynPlugin
{
	public Automation()
	{
		SynEngine.AddAutoParser(new OpenDoorTerm());
		SynEngine.AddGear(new AutomationGear());
		SynEngine.LoadComplete += AddChoice;
	}
	public void AddChoice()
	{
		SynEngine.Avatar.SpeechRecognizers.LoadGrammar("how are you");
		SynEngine.Avatar.SpeechRecognizers.LoadGrammar(this.Document.GetElementsByTagName("speech").Item(0));
	}
	public sealed class OpenDoorTerm : SynTerm
	{
		public OpenDoorTerm()
		{
			this.AddTernPattern("\\b(open door)\\b");
		}
	}

	public sealed class AutomationGear : SynGear
	{
		public void OpenDoor(OpenDoorTerm cmd, IntegerTerm operand)
		{
			cmd.TermCaller.Respond("Door number " + operand.Value.ToString + " has been opened");
		}
	}
}

Visual Basic Code

Imports SynModule
Imports SynModule.Terms

Public Class Automation : Inherits SynPlugin
    Sub New()
        SynEngine.AddAutoParser(New OpenDoorTerm)
        SynEngine.AddGear(New AutomationGear)
        AddHandler SynEngine.LoadComplete, AddressOf AddChoice
    End Sub
    Public Sub AddChoice()
        SynEngine.Avatar.SpeechRecognizers.LoadGrammar("how are you")
        SynEngine.Avatar.SpeechRecognizers.LoadGrammar(Me.Document.GetElementsByTagName("speech").Item(0))
    End Sub
    Public NotInheritable Class OpenDoorTerm : Inherits SynTerm
        Sub New()
            Me.AddTernPattern("\b(open door)\b")
        End Sub
    End Class

    Public NotInheritable Class AutomationGear : Inherits SynGear
        Public Sub OpenDoor(cmd As OpenDoorTerm, operand As IntegerTerm)
            cmd.TermCaller.Respond("Door number " & operand.Value.ToString & " has been opened")
        End Sub
    End Class
End Class
As you can see that you can add Voice-Choice after the loading is complete. You can even use an XML element to add multiple choices. You can open the Messaging.xml file in the Settings Folder and refer the "Speech" Tag

Here is a sample:

XML Code

<speech>
    <choice>login to google</choice>
    <choice>login to msn</choice>
    <choice>log out of google</choice>
    <choice>disconnect from google</choice>
    <choice>log out of msn</choice>
    <choice>disconnect from msn</choice>
  </speech>

Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 2 guests