Thank you for being a valued part of the CNET community. As of December 1, 2020, the forums are in read-only format. In early 2021, CNET Forums will no longer be available. We are grateful for the participation and advice you have provided to one another over the years.

Thanks,

CNET Support

Question

C# and razer kraken headphones

Mar 29, 2018 6:16AM PDT

I am trying to make a chatbot on C#. For some reason my Razer kraken headphones cant pick up any voice commands. I know my headset is working because I use it to talk to my friends over discord or skype. I know the programe I wrote is working since it works with other microphones.

If anyone knows what I should do please help me

thanks in advance Happy

Discussion is locked

- Collapse -
Answer
No pun intended.
Mar 29, 2018 9:43AM PDT

It sounds as if your app is not setting the audio source. Try setting that first using the Windows controls before your app as you work on adding source control to your app.

- Collapse -
Help
Mar 30, 2018 9:13AM PDT

Could you maybe help with that? I am not an experienced C# user and I don't really know what this means.

Thanks in advance

- Collapse -
Sorry no.
Mar 30, 2018 9:22AM PDT

To write apps you would know how to set the source in the windows mixer manually. Not to upset you but basics like that should be mastered before coding.

- Collapse -
Answer
There are programmer forums.
Mar 30, 2018 9:27AM PDT

But all ask you to show your work to get it done as well as your code that failed.

This is a discussion forum so I'll share what I see a lot of today. It's not good. Many post to the coding forums with no code or blatant "give me the code" and get rebuffed immediately. Some refuse to do research. Again, no one helps those that don't help themselves.

In your case it looks like the audio source needs to be changed. Just like Audacity folk go on and on about it not recording and ignore priors about setting the audio source. I worry that many of today's PC owners are too dependent on support.

- Collapse -
The code then
Mar 31, 2018 1:46AM PDT

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

namespace Voice_Bot_v2
{
public partial class Form1 : Form
{
String[] grammarFile = (File.ReadAllLines(@"C:\Voice Bot\grammar.txt"));
String[] responseFile = (File.ReadAllLines(@"C:\Voice Bot\response.txt"));

SpeechSynthesizer speechSynth = new SpeechSynthesizer();
Boolean wake = true;

Choices grammarList = new Choices();
SpeechRecognitionEngine speechRecognition = new SpeechRecognitionEngine();

public Form1()
{
grammarList.Add(grammarFile);
Grammar grammar = new Grammar(new GrammarBuilder(grammarList));

try
{
speechRecognition.RequestRecognizerUpdate();
speechRecognition.LoadGrammar(grammar);
speechRecognition.SpeechRecognized += rec_speechRecognized;
speechRecognition.SetInputToDefaultAudioDevice();
speechRecognition.RecognizeAsync(RecognizeMode.Multiple);
}
catch { return; }

speechSynth.SelectVoiceByHints(VoiceGender.Female);


InitializeComponent();
}

public void say(String text)
{
speechSynth.SpeakAsync(text);
}

private void rec_speechRecognized(object sender, SpeechRecognizedEventArgs e)
{
String result = e.Result.Text;
int resp = Array.IndexOf(grammarFile, result);

if (result.Contains("wake"))
{
wake = true;
say("activated");
}
if (result.Contains("sleep"))
{
wake = false;
say("deactivated");
}

if (result.Contains("hey"))
{
say("I am here");
wake = true;
System.Threading.Thread.Sleep(10000);
wake = false;
}



if (wake == true)
{



if (responseFile[resp].IndexOf('+') == 0)
{
List<string> responses = responseFile[resp].Replace('+', ' ').Split('/').Reverse().ToList();
Random r = new Random();
say(responses[r.Next(responses.Count)]);
}
else
{
if (responseFile[resp].IndexOf('*') == 0)
{
if (result.Contains("date"))
{
say(DateTime.Now.ToString(@"M/d/yyyy"));
}
if (result.Contains("google"))
{
Process.Start("http://google.com");
}
if (result.Contains("youtube"))
{
Process.Start("https://www.youtube.com");
}



if (result.Contains("open grammar"))
{
Process.Start(@"C:\Voice Bot\grammar.txt");
}
if (result.Contains("open responds"))
{
Process.Start(@"C:\Voice Bot\response.txt");
}



if (result.Contains("time"))
{
say(DateTime.Now.ToString(@"hh\:mm ss"));
}
}
else
{
say(responseFile[resp]);
}
}

}

}

private void Form1_Load(object sender, EventArgs e)
{

}
}
}

- Collapse -
Visual studio's
Mar 31, 2018 1:48AM PDT

So I am building this app in visual studio's. All the References are added. I set the audio and listening in the Try loop:
try
{
speechRecognition.RequestRecognizerUpdate();
speechRecognition.LoadGrammar(grammar);
speechRecognition.SpeechRecognized += rec_speechRecognized;
speechRecognition.SetInputToDefaultAudioDevice();
speechRecognition.RecognizeAsync(RecognizeMode.Multiple);
}
catch { return; }

Where I say to pet it into my Default Audio Device (which is set to my Razer Kraken). So basically I set my audio source right?

- Collapse -
See what a mess this forum makes of that?
Mar 31, 2018 9:06AM PDT

You need to get on the programming forums which handle code snippets. Try DaniWeb, CodeProject and such since here your code is mangled by the forum and unreadable.

Also, I see no code in your code to switch to another audio input. This is why I feel you might be very new to Windows and/or coding. Why not set the audio input before you run your app?