コード例 #1
0
        public void TestIsWavForTrue()
        {
            WavConverter converter = new WavConverter();
            bool         result    = converter.isWav(@"C:\Users\admin\Desktop\AudioRecognitionApp\AudioRecognitionAppTest\temp\Temp Record.wav");

            Assert.IsTrue(result);
        }
コード例 #2
0
        public void Conversionless()
        {
            WavConverter.Convert(AudioFiles.WavFilename, DefaultOutputPath);
            var existsOutputPath = File.Exists(DefaultOutputPath);

            Assert.False(existsOutputPath);
        }
コード例 #3
0
        public void ConversionTest(
            string inputPath, SampleRate sampleRate, BitRate bitRate, ChannelFormat channelFormat)
        {
            var inputFileName       = Path.GetFileNameWithoutExtension(inputPath);
            var actualSampleRate    = SampleRateHelper.GetSampleRate(sampleRate);
            var actualBitRate       = BitRateHelper.GetBitRate(bitRate);
            var actualChannelsCount = ChannelFormatHelper.GetChannelsCount(channelFormat);
            var fileName            = $"{inputFileName}-SR{actualSampleRate}-BR{actualBitRate}-CF{actualChannelsCount}";
            var outputPath          = string.Format(OutputPathFormat, fileName);

            WavConverter.Convert(inputPath, outputPath, sampleRate, channelFormat, bitRate);

            using (var inputReader = new AudioFileReader(inputPath))
                using (var outputReader = new WaveFileReader(outputPath))
                {
                    Assert.Equal(actualSampleRate, outputReader.WaveFormat.SampleRate);
                    Assert.Equal(actualBitRate, outputReader.WaveFormat.BitsPerSample);
                    Assert.Equal(actualChannelsCount, outputReader.WaveFormat.Channels);
                    Assert.InRange(
                        inputReader.TotalTime, outputReader.TotalTime - _totalTimeDelta,
                        outputReader.TotalTime + _totalTimeDelta);
                }

#if !DEBUG
            DeleteIfExists(outputPath);
#endif
        }
コード例 #4
0
        public void TestIsWavForFalse()
        {
            WavConverter converter = new WavConverter();
            bool         result    = converter.isWav(@"C:\Users\admin\Desktop\AudioRecognitionApp\AudioRecognitionAppTest\temp\02 - Angel Of Small Death And The Codeine Scene.mp3");

            Assert.IsFalse(result);
        }
コード例 #5
0
        private void addSongsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFile = new OpenFileDialog();

            openFile.Filter      = "all files (*.*)|*.*|mp3 files (*.mp3)|*.mp3|wav files (*.wav)|*.wav";
            openFile.Multiselect = true;
            if (openFile.ShowDialog() == DialogResult.OK)
            {
                fingerPrinter = new AudioFingerPrinter();
                wavConverter  = new WavConverter();

                foreach (var file in openFile.FileNames)
                {
                    if (wavConverter.isWav(file))
                    {
                        songs.Add(new Song(Path.GetFileNameWithoutExtension(file), fingerPrinter.determineKeyPoints(wavConverter.convertWavFile(file))));
                    }
                    else
                    {
                        wavConverter.mp3ToWav(file);
                        songs.Add(new Song(Path.GetFileNameWithoutExtension(file), fingerPrinter.determineKeyPoints(wavConverter.convertWavFile(wavConverter.mp3Path))));
                    }
                }
                MessageBox.Show("Songs successfully added!");
            }
        }
コード例 #6
0
        private async Task <HttpResponseMessage> CreateEnrollment(string identificationProfileId, IFormFile audioFile)
        {
            var client      = new HttpClient();
            var queryString = HttpUtility.ParseQueryString(string.Empty);

            // Request headers
            string azureKey = await _secretService.GetSecret(_appSettings.CognitiveServiceKey);

            client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", azureKey);

            // Request parameters
            var uri = $"https://westus.api.cognitive.microsoft.com/spid/v1.0/verificationProfiles/{identificationProfileId}/enroll?" + queryString;

            HttpResponseMessage response;

            // Request body
            byte[] convertedWav;
            using (var br = new BinaryReader(audioFile.OpenReadStream()))
            {
                var rawData = br.ReadBytes((int)audioFile.OpenReadStream().Length);
                convertedWav = WavConverter.ConvertToAzureWav(rawData);
            }
            //System.IO.File.WriteAllBytes("file.wav", convertedWav);
            //byte[] byteData = Encoding.UTF8.GetBytes;

            using (var content = new ByteArrayContent(convertedWav))
            {
                content.Headers.ContentType = new MediaTypeHeaderValue("multipart/form-data");
                response = await client.PostAsync(uri, content);

                // DEBUG - uncomment for better json reading feeling
                return(response);
            }
        }
コード例 #7
0
        static void Main(string[] args)
        {
            var currentDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            var inputFiles       = Directory.EnumerateFiles(currentDirectory, "*.wav", SearchOption.TopDirectoryOnly);

            foreach (var file in inputFiles)
            {
                var fileName       = Path.GetFileNameWithoutExtension(file);
                var outputFileName = $"{fileName}-out.wav";
                var outputPath     = Path.Combine(currentDirectory, "Output", outputFileName);
                var thread         = new Thread(() =>
                {
                    Debug.WriteLine($"Converting {fileName}...");

                    try
                    {
                        WavConverter.Convert(file, outputPath, SampleRate.Low, ChannelFormat.Mono, BitRate.Low);
                    }
                    catch (InvalidDataException)
                    {
                        Debug.WriteLine($":-S Ops, unsupported format: {fileName}");
                    }
                    catch (Exception exception)
                    {
                        Debug.WriteLine($":,-( Ops, {exception.Message}: {fileName}");
                    }
                    finally
                    {
                        Debug.WriteLine($"Done!: {fileName}");
                    }
                });
                thread.Start();
            }
        }
コード例 #8
0
        private async Task <HttpResponseMessage> Verify(string verificationProfileId, IFormFile audioFile)
        {
            var client      = new HttpClient();
            var queryString = HttpUtility.ParseQueryString(string.Empty);

            // Request headers
            string azureKey = await _secretService.GetSecret(_appSettings.CognitiveServiceKey);// _config["CognitiveServiceKey"];

            client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", azureKey);

            var uri = $"https://westus.api.cognitive.microsoft.com/spid/v1.0/verify?verificationProfileId={verificationProfileId}&" + queryString;

            HttpResponseMessage response;

            // Request body
            byte[] convertedWav;
            using (var br = new BinaryReader(audioFile.OpenReadStream()))
            {
                var rawData = br.ReadBytes((int)audioFile.OpenReadStream().Length);
                convertedWav = WavConverter.ConvertToAzureWav(rawData);
            }

            using (var content = new ByteArrayContent(convertedWav))
            {
                content.Headers.ContentType = new MediaTypeHeaderValue("multipart/form-data");
                response = await client.PostAsync(uri, content);

                dynamic responseJson = JsonConvert.DeserializeObject(await response.Content.ReadAsStringAsync());

                return(response);
            }
        }
コード例 #9
0
        public void DifferentOutputDirectoryTest()
        {
            var outputPath = Path.Combine(DefaultOutputDirectory, DefaultOutputPath);

            WavConverter.Convert(AudioFiles.WavFilename, outputPath, SampleRate.Low, ChannelFormat.Mono, BitRate.Low);

#if !DEBUG
            DeleteIfExists(outputPath);
            Directory.Delete(DefaultOutputDirectory);
#endif
        }
コード例 #10
0
        public void TestConvertWavFileForFalse()
        {
            WavConverter converter = new WavConverter();

            byte[] result = converter.convertWavFile(@"C:\Users\admin\Desktop\AudioRecognitionApp\AudioRecognitionAppTest\temp\Temp Record.wav");
            using (WaveStream stream = new WaveFileReader(@"C:\Users\admin\Desktop\AudioRecognitionApp\AudioRecognitionAppTest\temp\Temp Song 2.wav"))
            {
                int sampleRate = stream.WaveFormat.AverageBytesPerSecond;
                Assert.AreNotEqual(44100, sampleRate);
            }
        }
コード例 #11
0
        public void TestDetermineKeyPoints()
        {
            AudioFingerPrinter audioFingerPrinter = new AudioFingerPrinter();
            WavConverter       converter          = new WavConverter();

            byte[] array = new byte[1024];
            for (int i = 0; i < 1024; i++)
            {
                array[i] = 100;
            }
            List <DataPoint> points = audioFingerPrinter.determineKeyPoints(array);
            long             expect = 800402610;
            long             result = points[0].hash;

            Assert.AreEqual(expect, result);
        }
コード例 #12
0
        private void recognizeBtn_Click(object sender, EventArgs e)
        {
            if (songs.Count == 0)
            {
                MessageBox.Show("List of songs is empty!");
                return;
            }
            if (microphone == null && songPath == null)
            {
                MessageBox.Show("Please, record song or open it on your disk driver!");
                return;
            }
            matchesGridView.Rows.Clear();
            matchesGridView.Refresh();
            fingerPrinter = new AudioFingerPrinter();

            List <DataPoint> dataCheck;
            WavConverter     converter = new WavConverter();

            if (microphone != null)
            {
                dataCheck = fingerPrinter.determineKeyPoints(converter.convertWavFile(songRecorder.path));
            }
            else
            {
                if (converter.isWav(songPath))
                {
                    var song1 = converter.convertWavFile(songPath);
                    dataCheck = fingerPrinter.determineKeyPoints(converter.convertWavFile(songPath));
                }
                else
                {
                    converter.mp3ToWav(songPath);
                    dataCheck = fingerPrinter.determineKeyPoints(converter.convertWavFile(converter.mp3Path));
                }
            }

            List <Match> matches = findMatches(dataCheck, songs);

            writeMatches(matches);
            microphone         = null;
            songPath           = null;
            songPathField.Text = "";
        }
コード例 #13
0
 public void UnexistingInputTest()
 {
     Assert.Throws <FileNotFoundException>(
         () => WavConverter.Convert("Foo.wav", DefaultOutputPath, SampleRate.Low));
 }
コード例 #14
0
 public void ULauConversionTest()
 {
     Assert.Throws <InvalidDataException>(
         () => WavConverter.Convert(AudioFiles.WavSR44100BR32CF2ULauFilename, DefaultOutputPath));
 }
コード例 #15
0
 /**<summary>Replaces a sound content file.</summary>*/
 private static void ReplaceSound(string name, string outputFile)
 {
     WavConverter.Convert(GetSound(name), Path.Combine(SoundDir, outputFile));
 }