Пример #1
0
        public void IBM_audio_guess()
        {
            if (IBM_APIkey.TextLength == 0 || IBM_URL.TextLength == 0)
            {
                return;
            }
            IamAuthenticator authenticator = new IamAuthenticator(
                apikey: IBM_APIkey.Text);

            SpeechToTextService service = new SpeechToTextService(authenticator);

            service.SetServiceUrl(IBM_URL.Text);
            var model_to_use = "en-US_BroadbandModel";

            using (var reader = new WaveFileReader(folder_path + "\\" + transcriptions.ElementAt(current_line_number).Key))
            {
                if (reader.WaveFormat.SampleRate < 16000)
                {
                    model_to_use = "en-US_NarrowbandModel";
                }
            }

            DetailedResponse <SpeechRecognitionResults> result = service.Recognize(
                audio: File.ReadAllBytes(folder_path + "\\" + transcriptions.ElementAt(current_line_number).Key),
                contentType: "audio/wav",
                profanityFilter: false,
                model: model_to_use
                );
            SpeechRecognitionResults     results      = result.Result;
            SpeechRecognitionResult      final_result = results.Results[0];
            SpeechRecognitionAlternative real_result  = final_result.Alternatives[0];

            TranscriptionBox.Text = real_result.Transcript;
            SaveTranscriptionLine();
        }
Пример #2
0
        public void SpeechToTextV1WithLoadedCredentials_Success()
        {
            SpeechToTextService service = new SpeechToTextService();

            Assert.IsTrue(!string.IsNullOrEmpty(service.ApiKey));
            Assert.IsTrue(!string.IsNullOrEmpty(service.Url));
        }
Пример #3
0
        // GET: Recipes
        public ActionResult Index()
        {
            if (TempData["RecipeResults"] != null)
            {
                var model = TempData["RecipeResults"] as List <RecipeResult>;
                return(View(model));
            }

            var binDirectoryPath = Server.MapPath("~/bin");
            var wavFileLocation  = string.Format(@"{0}\Assets\AudioFile.wav", binDirectoryPath);

            var response   = SpeechToTextService.Interupt(wavFileLocation);
            var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
            var result     = serializer.Deserialize <CogResponse>(response);

            var items = result.Results.First().Lexical.Split(' ').ToList();

            var output = RecipeLookupService.Query(items);

            var topOne = output.Results.First().Title;

            var reply = string.Format("There are many options but aye recommend {0}", topOne);

            TextToSpeechService.Speak(reply);
            return(View(output.Results));
        }
Пример #4
0
        public async Task <IActionResult> SpeechToText([FromBody] JObject request)
        {
            var         watch      = System.Diagnostics.Stopwatch.StartNew();
            string      methodName = "SpeechToText";
            ResponseDTO response   = new ResponseDTO();

            try
            {
                Log.Write(appSettings, LogEnum.DEBUG.ToString(), label, className, methodName, $"REQUEST: {JsonConvert.SerializeObject(request)}");
                SpeechToTextRequest requestBody = request.ToObject <SpeechToTextRequest>();
                response.Result = await SpeechToTextService.SpeechToText(appSettings, requestBody);

                response.Success = true;
                watch.Stop();
                Log.Write(appSettings, LogEnum.DEBUG.ToString(), label, className, methodName, $"RESULT: {JsonConvert.SerializeObject(response)} Execution Time: {watch.ElapsedMilliseconds} ms");
                return(Ok(response));
            }
            catch (Exception e)
            {
                response.Success = false;
                response.Msg     = e.Message;
                watch.Stop();
                Log.Write(appSettings, LogEnum.ERROR.ToString(), label, className, methodName, $"ERROR: {JsonConvert.SerializeObject(request)}");
                Log.Write(appSettings, LogEnum.ERROR.ToString(), label, className, methodName, $"ERROR: {e.Source + Environment.NewLine + e.Message + Environment.NewLine + e.StackTrace}");
                return(BadRequest(response));
            }
        }
Пример #5
0
        private IEnumerator CreateService()
        {
            if (string.IsNullOrEmpty(iamApikey))
            {
                throw new IBMException("Plesae provide IAM ApiKey for the service.");
            }

            //  Create authenticator and instantiate service
            Authenticator speechToTextAuthenticator = new IamAuthenticator(
                apikey: iamApikey,
                url: serviceUrl
                );

            //  Wait for authenticator
            while (!speechToTextAuthenticator.CanAuthenticate())
            {
                yield return(null);
            }

            _service = new SpeechToTextService(speechToTextAuthenticator);
            _service.StreamMultipart = true;

            Active = true;
            StartRecording();
        }
Пример #6
0
        public void AddCorpus()
        {
            IamAuthenticator authenticator = new IamAuthenticator(
                apikey: "{apikey}");

            SpeechToTextService service = new SpeechToTextService(authenticator);

            service.SetServiceUrl("{serviceUrl}");

            DetailedResponse <object> result = null;

            using (FileStream fs = File.OpenRead("corpus1.txt"))
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    fs.CopyTo(ms);
                    result = service.AddCorpus(
                        customizationId: "{customizationId}",
                        corpusFile: ms,
                        corpusName: "corpus1"
                        );
                }
            }

            Console.WriteLine(result.Response);
            // Poll for language model status.
        }
Пример #7
0
    IEnumerator Start()
    {
        LogSystem.InstallDefaultReactors();

        //  Create credential and instantiate service
        TokenOptions tokenOptions = new TokenOptions()
        {
            IamApiKey = _apiKey
        };
        var credentials = new Credentials(tokenOptions, _url);

        //  Wait for tokendata
        Debug.Log("Watson: waiting for token data");
        while (!credentials.HasIamTokenData())
        {
            yield return(null);
        }
        Debug.Log("Watson: got token data; starting service");

        _speechToText = new SpeechToTextService(credentials);
        alternatives  = new List <string>();

        if (!pushToTalk)
        {
            Active = true;
            StartRecording();
        }
        else
        {
            onNotListening.Invoke();
        }
    }
Пример #8
0
        public void AddCorpus()
        {
            TokenOptions tokenOptions = new TokenOptions()
            {
                IamApiKey  = apikey,
                ServiceUrl = url
            };

            SpeechToTextService service = new SpeechToTextService(tokenOptions);

            DetailedResponse <object> result = null;

            using (FileStream fs = File.OpenRead(corpusPath))
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    fs.CopyTo(ms);
                    result = service.AddCorpus(
                        customizationId: customizationId,
                        corpusName: corpusName,
                        corpusFile: ms
                        );
                }
            }

            Console.WriteLine(result.Response);
        }
Пример #9
0
        public void AddWord()
        {
            TokenOptions tokenOptions = new TokenOptions()
            {
                IamApiKey  = apikey,
                ServiceUrl = url
            };

            SpeechToTextService service = new SpeechToTextService(tokenOptions);

            var customWord = new CustomWord()
            {
                DisplayAs  = ".NET",
                SoundsLike = new List <string>()
                {
                    "dotnet"
                },
                Word = "dotnet"
            };

            var result = service.AddWord(
                customizationId: customizationId,
                wordName: "dotnet",
                word: "dotnet",
                soundsLike: new List <string>()
            {
                "dotnet"
            },
                displayAs: ".NET"
                );

            Console.WriteLine(result.Response);
        }
 public void OnDisable()
 {
     Log.Debug("SpeechListener.OnDisable()", "called", new object[] {});
     StopRecording();
     this.Active   = false;
     _speechToText = null;
 }
        public void Setup()
        {
            if (string.IsNullOrEmpty(credentials))
            {
                try
                {
                    credentials = Utility.SimpleGet(
                        Environment.GetEnvironmentVariable("VCAP_URL"),
                        Environment.GetEnvironmentVariable("VCAP_USERNAME"),
                        Environment.GetEnvironmentVariable("VCAP_PASSWORD")).Result;
                }
                catch (Exception e)
                {
                    Console.WriteLine(string.Format("Failed to get credentials: {0}", e.Message));
                }

                Task.WaitAll();

                var vcapServices = JObject.Parse(credentials);
                _endpoint = vcapServices["speech_to_text"]["url"].Value <string>();
                _username = vcapServices["speech_to_text"]["username"].Value <string>();
                _password = vcapServices["speech_to_text"]["password"].Value <string>();
            }

            _service          = new SpeechToTextService(_username, _password);
            _service.Endpoint = _endpoint;
        }
Пример #12
0
    public override IEnumerator CreateService()
    {
        //  Create credential and instantiate service
        Credentials credentials = null;

        //  Authenticate using iamApikey
        TokenOptions tokenOptions = new TokenOptions()
        {
            IamApiKey = _iamApikey
        };

        credentials = new Credentials(tokenOptions, _serviceUrl);

        //  Wait for tokendata
        while (!credentials.HasIamTokenData())
        {
            yield return(null);
        }

        _service = new SpeechToTextService(credentials)
        {
            StreamMultipart = true
        };

        Debug.Log("Created STT Service!");
        OnListen();
    }
Пример #13
0
        static void Main(string[] args)
        {
            ISpeechToTextService _speechToText = new SpeechToTextService("<username>", "<password>");

            using (FileStream fs = File.OpenRead("test-audio.wav"))
            {
                Console.WriteLine("\nCalling RecognizeBody...");
                var speechEvent = _speechToText.Recognize(fs.GetMediaTypeFromFile(),
                                                          fs);

                Console.WriteLine("speechEvent received...");
                if (speechEvent.Results != null || speechEvent.Results.Count > 0)
                {
                    foreach (SpeechRecognitionResult result in speechEvent.Results)
                    {
                        if (result.Alternatives != null && result.Alternatives.Count > 0)
                        {
                            foreach (SpeechRecognitionAlternative alternative in result.Alternatives)
                            {
                                Console.WriteLine(string.Format("{0}, {1}", alternative.Transcript, alternative.Confidence));
                            }
                        }
                    }
                }
            }

            Console.ReadKey();
        }
Пример #14
0
        public void AddWord()
        {
            IamConfig config = new IamConfig(
                apikey: apikey
                );

            SpeechToTextService service = new SpeechToTextService(config);

            service.SetEndpoint(url);

            var customWord = new CustomWord()
            {
                DisplayAs  = ".NET",
                SoundsLike = new List <string>()
                {
                    "dotnet"
                },
                Word = "dotnet"
            };

            var result = service.AddWord(
                customizationId: customizationId,
                wordName: "dotnet",
                word: "dotnet",
                soundsLike: new List <string>()
            {
                "dotnet"
            },
                displayAs: ".NET"
                );

            Console.WriteLine(result.Response);
        }
Пример #15
0
        private IEnumerator CreateService()
        {
            if (string.IsNullOrEmpty(_iamApikey))
            {
                throw new IBMException("Plesae provide IAM ApiKey for the service.");
            }

            IamAuthenticator authenticator = new IamAuthenticator(apikey: _iamApikey);

            //  Wait for tokendata
            while (!authenticator.CanAuthenticate())
            {
                yield return(null);
            }

            _service = new SpeechToTextService(authenticator);
            if (!string.IsNullOrEmpty(_serviceUrl))
            {
                _service.SetServiceUrl(_serviceUrl);
            }
            _service.StreamMultipart = true;

            Active = true;
            StartRecording();
        }
Пример #16
0
        public void SetServiceFromWrapper(SpeechToTextService service)
        {
            _service = service;
            _service.StreamMultipart = true;

            Active = true;
        }
Пример #17
0
        public void AddCorpus()
        {
            IamConfig config = new IamConfig(
                apikey: apikey
                );

            SpeechToTextService service = new SpeechToTextService(config);

            service.SetEndpoint(url);

            DetailedResponse <object> result = null;

            using (FileStream fs = File.OpenRead(corpusPath))
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    fs.CopyTo(ms);
                    result = service.AddCorpus(
                        customizationId: customizationId,
                        corpusName: corpusName,
                        corpusFile: ms
                        );
                }
            }

            Console.WriteLine(result.Response);
        }
Пример #18
0
        private bool IsTrainingComplete()
        {
            _speechToText          = new SpeechToTextService(_username, _password);
            _speechToText.Endpoint = _endpoint;

            var result = _speechToText.ListCustomModel(_createdCustomizationID);

            string status = result.Status.ToLower();

            Console.WriteLine(string.Format("Classifier status is {0}", status));

            if (status == "ready" || status == "available")
            {
                autoEvent.Set();
            }
            else
            {
                Task.Factory.StartNew(() =>
                {
                    System.Threading.Thread.Sleep(5000);
                    IsTrainingComplete();
                });
            }

            return(result.Status.ToLower() == "ready" || result.Status.ToLower() == "available");
        }
Пример #19
0
        public void t07_Recognize_WithSession_FormData_Sucess()
        {
            _speechToText =
                new SpeechToTextService(_username, _password);

            string modelName = "en-US_BroadbandModel";

            var session =
                _speechToText.CreateSession(modelName);

            FileStream audio =
                File.OpenRead(@"SpeechToTextTestData\test-audio.wav");

            var results =
                _speechToText.RecognizeWithSession(session.SessionId,
                                                   audio.GetMediaTypeFromFile(),
                                                   new Metadata()
            {
                PartContentType = audio.GetMediaTypeFromFile()
            },
                                                   audio);

            Assert.IsNotNull(results);
            Assert.IsNotNull(results.Results);
            Assert.IsTrue(results.Results.Count > 0);
            Assert.IsTrue(results.Results.First().Alternatives.Count > 0);
            Assert.IsNotNull(results.Results.First().Alternatives.First().Transcript);
        }
Пример #20
0
        private void button4_Click(object sender, EventArgs e)
        {
            try
            {
                mciSendString("save meuaudio arquivo.wav", null, 0, IntPtr.Zero);
                mciSendString("close meuaudio", null, 0, IntPtr.Zero);


                IamAuthenticator authenticator = new IamAuthenticator(
                    apikey: "0glqYYg5lpaDz2LNStEFtvowIdC0ditJf-3QnGsO5rfr");

                SpeechToTextService service = new SpeechToTextService(authenticator);
                service.SetServiceUrl("https://stream.watsonplatform.net/speech-to-text/api");

                var result = service.Recognize(
                    audio: File.ReadAllBytes("arquivo.wav"),
                    contentType: "audio/wav",
                    model: "pt-BR_NarrowbandModel");



                string voz = result.Result.Results.First().Alternatives.First().Transcript;


                txtMensagem.Text = voz;
            }
            catch (Exception)
            {
                MessageBox.Show("Ocorreu um erro desconhecido. Tente novamente.");
            }
        }
Пример #21
0
        public void AddWords_Success()
        {
            IClient  client  = Substitute.For <IClient>();
            IRequest request = Substitute.For <IRequest>();

            client.PostAsync(Arg.Any <string>())
            .Returns(request);

            SpeechToTextService service = new SpeechToTextService(client);

            var customizationId = "customizationId";
            var words           = new List <CustomWord>();

            var result = service.AddWords(customizationId: customizationId, words: words);

            JObject bodyObject = new JObject();

            if (words != null && words.Count > 0)
            {
                bodyObject["words"] = JToken.FromObject(words);
            }
            var json = JsonConvert.SerializeObject(bodyObject);

            request.Received().WithBodyContent(Arg.Is <StringContent>(x => x.ReadAsStringAsync().Result.Equals(json)));
            client.Received().PostAsync($"{service.ServiceUrl}/v1/customizations/{customizationId}/words");
        }
Пример #22
0
 public void CreateClients()
 {
     try
     {
         if (settingsService.settings.ibmSettings.textToSpeechAPIKey != "" && settingsService.settings.ibmSettings.speechToTextAPIKey != "" &&
             settingsService.settings.ibmSettings.speechToTextURL != "" && settingsService.settings.ibmSettings.textToSpeechURL != "")
         {
             textToSpeechTokenOptions = new TokenOptions
             {
                 IamApiKey  = settingsService.settings.ibmSettings.textToSpeechAPIKey,
                 ServiceUrl = settingsService.settings.ibmSettings.textToSpeechURL
             };
             speechToTextTokenOptions = new TokenOptions
             {
                 IamApiKey  = settingsService.settings.ibmSettings.speechToTextAPIKey,
                 ServiceUrl = settingsService.settings.ibmSettings.speechToTextURL
             };
             textToSpeechClient = new TextToSpeechService(textToSpeechTokenOptions);
             speechToTextClient = new SpeechToTextService(speechToTextTokenOptions);
         }
     }
     catch (Exception e)
     {
         Console.WriteLine($"IBM credentials not set. Error: {e}");
         MessageBox.Show($"IBM credentials not set. Error: {e}");
     }
 }
Пример #23
0
        public void CreateAcousticModel_Success()
        {
            IClient  client  = Substitute.For <IClient>();
            IRequest request = Substitute.For <IRequest>();

            client.PostAsync(Arg.Any <string>())
            .Returns(request);

            SpeechToTextService service = new SpeechToTextService(client);

            var name          = "name";
            var baseModelName = "baseModelName";
            var description   = "description";

            var result = service.CreateAcousticModel(name: name, baseModelName: baseModelName, description: description);

            JObject bodyObject = new JObject();

            if (!string.IsNullOrEmpty(name))
            {
                bodyObject["name"] = JToken.FromObject(name);
            }
            if (!string.IsNullOrEmpty(baseModelName))
            {
                bodyObject["base_model_name"] = JToken.FromObject(baseModelName);
            }
            if (!string.IsNullOrEmpty(description))
            {
                bodyObject["description"] = JToken.FromObject(description);
            }
            var json = JsonConvert.SerializeObject(bodyObject);

            request.Received().WithBodyContent(Arg.Is <StringContent>(x => x.ReadAsStringAsync().Result.Equals(json)));
        }
Пример #24
0
        private IEnumerator CreateService()
        {
            if (string.IsNullOrEmpty(_iamApikey))
            {
                throw new IBMException("Plesae provide IAM ApiKey for the service.");
            }

            //  Create credential and instantiate service
            Credentials credentials = null;

            //  Authenticate using iamApikey
            TokenOptions tokenOptions = new TokenOptions()
            {
                IamApiKey = _iamApikey
            };

            credentials = new Credentials(tokenOptions, _serviceUrl);

            //  Wait for tokendata
            while (!credentials.HasIamTokenData())
            {
                yield return(null);
            }

            _service = new SpeechToTextService(credentials);
            _service.StreamMultipart = true;

            Active = true;
            StartRecording();
        }
Пример #25
0
        private void Parar_Click(object sender, EventArgs e)
        {
            mciSendString("save meuaudio arquivo.wav", null, 0, IntPtr.Zero);
            mciSendString("close meuaudio", null, 0, IntPtr.Zero);


            IamAuthenticator authenticator = new IamAuthenticator(
                apikey: "0glqYYg5lpaDz2LNStEFtvowIdC0ditJf-3QnGsO5rfr");

            SpeechToTextService service = new SpeechToTextService(authenticator);

            service.SetServiceUrl("https://stream.watsonplatform.net/speech-to-text/api");

            var result = service.Recognize(
                audio: File.ReadAllBytes("arquivo.wav"),
                contentType: "audio/wav",
                model: "pt-BR_NarrowbandModel");



            string voz = result.Result.Results.First().Alternatives.First().Transcript;


            if (voz.Contains("mensagem"))
            {
                Telas.FrmWhatsApp wpp = new FrmWhatsApp();

                wpp.Show();

                this.Hide();
            }

            if (voz.Contains("fornecedor"))
            {
                Telas.FrmFornedor wpp = new FrmFornedor();

                wpp.Show();

                this.Hide();
            }

            if (voz.Contains("estoque"))
            {
                telas.Estoque wpp = new telas.Estoque();

                wpp.Show();

                this.Hide();
            }

            if (voz.Contains("financeiro"))
            {
                Telas.FrmFinanceiro wpp = new FrmFinanceiro();

                wpp.Show();

                this.Hide();
            }
        }
        public void GetModel_Without_ModelName()
        {
            IClient client = Substitute.For <IClient>();

            SpeechToTextService service = new SpeechToTextService(client);

            var models = service.GetModel(string.Empty);
        }
Пример #27
0
        private void Initialisation()
        {
            authenticator = new IamAuthenticator(
                apikey: this.Key
                );

            speechToTextService = new SpeechToTextService(authenticator);
            speechToTextService.SetServiceUrl(this.Url);
        }
Пример #28
0
        static void Main(string[] args)
        {
            var service = new SpeechToTextService("ee304a2438c44724a98a3d45724b61e8");

            service.Start("it works.wav", "");

            Console.WriteLine("Ready....");

            Console.ReadLine();
        }
Пример #29
0
        public static IBM.WatsonDeveloperCloud.SpeechToText.v1.Model.SpeechRecognitionResults SendMessageToAssistant(byte[] audio)
        {
            var _assistant = new SpeechToTextService(AppManagement.UserNameST, AppManagement.PasswordST);

            Stream stream = new MemoryStream(audio);

            var result = _assistant.Recognize("audio/flac", stream);//(AppManagement.WorkspaceIDST, messageRequest);

            return(result);
        }
Пример #30
0
        public void ConstructorExternalConfig()
        {
            var apikey = System.Environment.GetEnvironmentVariable("SPEECH_TO_TEXT_APIKEY");

            System.Environment.SetEnvironmentVariable("SPEECH_TO_TEXT_APIKEY", "apikey");
            SpeechToTextService service = Substitute.For <SpeechToTextService>();

            Assert.IsNotNull(service);
            System.Environment.SetEnvironmentVariable("SPEECH_TO_TEXT_APIKEY", apikey);
        }