Hello Ventuzians!
THE FORUMS ARE CLOSED!

Please join our discord server HERE!! << click me :D

We are shutting our Ventuz Forum, but don't worry, it will all be archived for you to search in if you have a query. From now on, please add all your comments, questions or observations into our Discord Server

Thanks for the great time - see you on discord!!
Dee, Karol, Daniel and the whoooole Product and Support team!

c# ventuz help

Q and A about functionality and how to solve a special task for your application.

Moderator: Support

Post Reply
User avatar
hgoodsir
Posts: 65
Joined: 05 Feb 2012, 16:17
Location: London
Contact:

c# ventuz help

Post by hgoodsir » 29 Jan 2015, 13:59

hi all,

just experimenting with c# in ventuz and a little stuck with abit of the script i have made text to speech work,
but now been trying to get speech to text.


when compile is says sRecognize does not exist and sRecognize_SpeechRecognized does not exist
i have look at examples and think its something to do with this private void but not really sure.

Code: Select all

private void sRecognize_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            if (e.Result.Text == "play")
            {
                Play();
            }
         }



Code: Select all

using System;
using Ventuz.Kernel;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Speech.Synthesis;
using System.Speech.Recognition;
using System.Threading;



public class Script : ScriptBase, System.IDisposable
{
    
	// This member is used by the Validate() method to indicate
	// whether the Generate() method should return true or false
	// during its next execution.
	private bool changed;
    
	// This Method is called if the component is loaded/created.
	public Script()
	{
		// Note: Accessing input or output properties from this method
		// will have no effect as they have not been allocated yet.
	}
    
	// This Method is called if the component is unloaded/disposed
	public virtual void Dispose()
	{
	
		
	}
    
	// This Method is called if an input property has changed its value
	public override void Validate()
	{
		// Remember: set changed to true if any of the output 
		// properties has been changed, see Generate()
		
		SpeechSynthesizer sSynth = new SpeechSynthesizer();
		PromptBuilder pBuilder = new PromptBuilder();
		SpeechRecognitionEngine sReconize = new SpeechRecognitionEngine();
		
		
		
		pBuilder.ClearContent();
		pBuilder.AppendText(text);
		sSynth.Speak(pBuilder);
		
		Choices sList = new Choices();
		sList.Add(new string[] {"play","stop"});
		Grammar gr = new Grammar (new GrammarBuilder(sList));
		try
		{
			sRecognize.RequestRecognizerUpdate();
			sRecognize.LoadGrammar(gr);
			sRecognize.SpeechRecognized += sRecognize_SpeechRecognized;
			sRecognize.SetInputToDefaultAudioDevice();
			sRecognize.RecognizeAsync(RecognizeMode.Multiple);
			sRecognize.Recognize();
		}
		catch
		{
			return;	
		}	
		
	}
    
	// This Method is called every time before a frame is rendered.
	// Return value: if true, Ventuz will notify all nodes bound to this
	//               script node that one of the script's outputs has a
	//               new value and they therefore need to validate. For
	//               performance reasons, only return true if output
	//               values really have been changed.
	public override bool Generate()
	{
		if (changed)
		{
			changed = false;
			return true;
		}

		return false;
	}
	
	// This Method is called if the function/method speak is invoked by the user or a bound event.
	// Return true, if this component has to be revalidated!
	public bool Onspeak(int arg)
	{
		
		return false;
	}
	
	// This Method is called if the function/method Method1 is invoked by the user or a bound event.
	// Return true, if this component has to be revalidated!
	public bool OnMethod1(int arg)
	{
		return false;
	}

}
	

zoidberg
Posts: 10
Joined: 22 Jan 2013, 11:14

Re: c# ventuz help

Post by zoidberg » 30 Jan 2015, 23:35

Hi,

sRecognize does not exist: Please check following line in your code:

Code: Select all

SpeechRecognitionEngine sReconize = new SpeechRecognitionEngine();
The g is missing in sReconize. That`s the reason for this error.

sRecognize_SpeechRecognized does not exist: You have to add this method at the end of the script node class:

Code: Select all

private void sRecognize_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            if (e.Result.Text == "play")
            {
                Play();
            }
         }
But you have to add the method PLAY as well to this script node. Otherwise you will get the next error message.

Here is the whole script node code. But SAVE ist missing ;-)

Code: Select all

using System;
using Ventuz.Kernel;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Speech.Synthesis;
using System.Speech.Recognition;
using System.Threading;



public class Script : ScriptBase, System.IDisposable
{
    
	// This member is used by the Validate() method to indicate
	// whether the Generate() method should return true or false
	// during its next execution.
	private bool changed;
    
	// This Method is called if the component is loaded/created.
	public Script()
	{
		// Note: Accessing input or output properties from this method
		// will have no effect as they have not been allocated yet.
	}
    
	// This Method is called if the component is unloaded/disposed
	public virtual void Dispose()
	{
   
      
	}
    
	// This Method is called if an input property has changed its value
	public override void Validate()
	{
		// Remember: set changed to true if any of the output 
		// properties has been changed, see Generate()
      
		SpeechSynthesizer sSynth = new SpeechSynthesizer();
		PromptBuilder pBuilder = new PromptBuilder();
		SpeechRecognitionEngine sRecognize = new SpeechRecognitionEngine();
      
      
      
		pBuilder.ClearContent();
		pBuilder.AppendText(text);
		sSynth.Speak(pBuilder);
      
		Choices sList = new Choices();
		sList.Add(new string[] {"play","stop"});
		Grammar gr = new Grammar (new GrammarBuilder(sList));
		try
		{
			sRecognize.RequestRecognizerUpdate();
			sRecognize.LoadGrammar(gr);
			sRecognize.SpeechRecognized += sRecognize_SpeechRecognized;
			sRecognize.SetInputToDefaultAudioDevice();
			sRecognize.RecognizeAsync(RecognizeMode.Multiple);
			sRecognize.Recognize();
		}
		catch
		{
			return;   
		}   
      
	}
    
	// This Method is called every time before a frame is rendered.
	// Return value: if true, Ventuz will notify all nodes bound to this
	//               script node that one of the script's outputs has a
	//               new value and they therefore need to validate. For
	//               performance reasons, only return true if output
	//               values really have been changed.
	public override bool Generate()
	{
		if (changed)
		{
			changed = false;
			return true;
		}

		return false;
	}
   
	// This Method is called if the function/method speak is invoked by the user or a bound event.
	// Return true, if this component has to be revalidated!
	public bool Onspeak(int arg)
	{
      
		return false;
	}
   
	// This Method is called if the function/method Method1 is invoked by the user or a bound event.
	// Return true, if this component has to be revalidated!
	public bool OnMethod1(int arg)
	{
		return false;
	}
	
	private void sRecognize_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
	{
		if (e.Result.Text == "play")
		{
			Play();
		}
	}
}
   
Best regards,
Anton

User avatar
hgoodsir
Posts: 65
Joined: 05 Feb 2012, 16:17
Location: London
Contact:

Re: c# ventuz help

Post by hgoodsir » 05 Feb 2015, 11:50

cool thanks Anton :)

Post Reply