IdentifySong() 공개 메소드

public IdentifySong ( Code item, String &errorMessage ) : EchonestResult
item echoprint_net.Data.Code
errorMessage String
리턴 EchonestResult
예제 #1
0
        static void Main(string[] args)
        {
            string[] files = Directory.GetFiles(@".\samplefiles");

            var api = new EchonestAPI();
            using (NCodegen codegen = new NCodegen(@"C:\dev\scratchpad\codegen", "codegen.exe", 10, 30))
            {
                codegen.Start((data) =>
                {
                    if (!String.IsNullOrEmpty(data.error))
                    {
                        Console.WriteLine("{0:HH:mm:ss} - {1}", DateTime.Now, data.error);
                        return;
                    }

                    string error;
                    var result = api.IdentifySong(data, out error);
                    PrintStatus(data, result, error);
                });

                foreach (var item in files)
                {
                    Console.WriteLine("{0:HH:mm:ss} - {1}", DateTime.Now, item);
                    codegen.AddFile(item);
                }
            }
        }
예제 #2
0
        private void Recording()
        {
            var mic = Microphone.Default;
            Log(String.Format("Using '{0}' as audio input...", mic.Name));
            var buffer = new byte[mic.GetSampleSizeInBytes(TimeSpan.FromSeconds(5))];

            int bytesRead = 0;
            string fileName = String.Empty;

            try
            {
                mic.Start();
                try
                {
                    Log(String.Format("{0:HH:mm:ss} Start recording audio stream...", DateTime.Now));
                    while (bytesRead < buffer.Length)
                    {
                        Thread.Sleep(1000);
                        var bytes = mic.GetData(buffer, bytesRead, (buffer.Length - bytesRead));
                        Log(String.Format("{0:HH:mm:ss} Saving {1} bytes to stream...", DateTime.Now, bytes));
                        bytesRead += bytes;
                    }
                    Log(String.Format("{0:HH:mm:ss} Finished recording audio stream...", DateTime.Now));
                }
                finally
                {
                    mic.Stop();
                }

                Func<byte, float> convert = (b) => System.Convert.ToSingle(b);
                var converter = new Converter<byte, float>(convert);
                float[] pcm = Array.ConvertAll<byte, float>(buffer, converter);

                Log(String.Format("{0:HH:mm:ss} Generating audio fingerprint...", DateTime.Now));
                var codeg = new CodegenCLI();
                String code = codeg.getCodeString(pcm, (uint)pcm.Length, 0);

                //CONVERT TO JSON
                var data = JsonConvert.DeserializeObject<Code>(code);
                if (!String.IsNullOrEmpty(data.error))
                {
                    Log(String.Format("{0:HH:mm:ss} - {1}", DateTime.Now, data.error));
                    return;
                }

                var api = new EchonestAPI();
                string error;
                Log(String.Format("{0:HH:mm:ss} Attempting to identify audio stream...", DateTime.Now));
                var result = api.IdentifySong(data, out error);
                switch (result)
                {
                    case EchonestResult.Success:
                        if (!String.IsNullOrEmpty(data.metadata.id))
                            Log(String.Format("{0:HH:mm:ss} - {1} {2}", DateTime.Now, data.metadata.id, data.metadata.title));
                        else
                            Log(String.Format("{0:HH:mm:ss} - NOT FOUND", DateTime.Now));
                        break;
                    case EchonestResult.NotFound:
                        Log(String.Format("{0:HH:mm:ss} - NOT FOUND", DateTime.Now));
                        break;
                    case EchonestResult.Error:
                        Log(String.Format("{0:HH:mm:ss} - ERROR: {1}", DateTime.Now, error));
                        break;
                }
            }
            catch (Exception ex)
            {
                Log(String.Format("{0:HH:mm:ss} - EXCEPTION: {1}", DateTime.Now, ex.Message));
            }
            finally
            {
                //xnadispatcher.Stop();
                ToggleControls(false);
            }
        }