示例#1
0
        public IActionResult Post(FileModel file)
        {
            var    uploads       = configuration.GetValue <string>("AppConfiguration:Uploads");
            var    bytes         = Convert.FromBase64String(file.File);
            string pathToWavFile = "";
            string path          = "";
            string result        = "";

            using (ZipArchive archive = new ZipArchive(new MemoryStream(bytes)))
            {
                foreach (ZipArchiveEntry entry in archive.Entries)
                {
                    string extension = Path.GetExtension(entry.FullName);
                    if (!string.IsNullOrEmpty(extension)) //make sure it's not a folder
                    {
                        path = Path.Combine(uploads, entry.FullName);
                        entry.ExtractToFile(path, true);
                        if (extension.ToLower() == ".wav")
                        {
                            pathToWavFile = path;
                        }
                    }
                    else
                    {
                        Directory.CreateDirectory(Path.Combine(uploads, entry.FullName));
                    }
                }

                var speechServices = new SpeechService();
                result = speechServices.RecognizeSpeechFromFileAsync(pathToWavFile).Result;
            }

            return(Ok(result));
        }