2

So I have:

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\Profile\Client\ System.Speech.dll

...and I can add the reference to Visual Studio but using System.Speech etc won't register with the console, and therefore speech synthesis and recognition does not work.

Would appreciate any and all help, thanks!

Ethan Moore
  • 383
  • 1
  • 5
  • 18
  • My description probably isn't correct, but I can get you the error code if that would help. When I type any of the `system.speech` commands in the main body of the code, it tells me that the command is unrecognized and the font color doesn't change as if it were an actual command. – Ethan Moore Feb 09 '16 at 00:55
  • Ah I see. Yes either "System.Speech" is wrong or you are missing an assembly reference. Let me look... –  Feb 09 '16 at 01:00
  • Okay. Here is the error: Severity Code Description Project File Line Suppression State Error Cannot find type System.MarshalByRefObject in module CommonLanguageRuntimeLibrary. AI1point0 Sorry if that looks messy. – Ethan Moore Feb 09 '16 at 01:02
  • 1
    @EthanMoore [`System.Speech`](https://msdn.microsoft.com/en-us/library/gg145021(v=vs.110).aspx) doesn't contain any types directly, you should probably be `using System.Speech.Recognition` or another sub-namespace – Mathias R. Jessen Feb 09 '16 at 01:02
  • 1
    @MathiasR.Jessen Sorry if I didn't make that clear. I have `using System.Speech.Recognition; using System.Speech.Synthesis;` at the top of the code, so that can't be the issue. I appreciate it though. – Ethan Moore Feb 09 '16 at 01:04

2 Answers2

3

You need to add a reference to the System.Speech assembly, then you are free to use speech like so:

using System;
using System.Speech; // <-- sounds like what you are using, not necessary for this example
using System.Speech.Recognition; // <--- you need this

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            using (SpeechRecognizer recognizer = new SpeechRecognizer())
            {
                // do something
            }
        }
    }
}

Adding reference

Just in case, here is the reference I am using (via project.References.Add Reference...):

enter image description here

It is not necessary to use the Browse function. I'm assuming you are not using COM too.

Tell me more

2

Its a little out of date but this tutorial shows you how to get started using the System.speech class

It sounds like what you are doing now is trying to use the class directly. The first step is to make an instance of the SpeechSynthesizer or SpeechRecognizer class with which you can perform the System.speech actions.

pkatsourakis
  • 1,024
  • 7
  • 20