예제 #1
0
 private void DoGetResult(ulong requestId)
 {
     try
     {
         RaiseOnRecongnitionStateChanged(ShazamRecognitionState.Matching, null);
         shazamRequest.requestId = requestId;
         shazamRequest.art_width = 520;
         var request = shazamRequest;
         var str     = request.requestId.ToString();
         var orbitPostRequestBuilder = new OrbitPostRequestBuilder(encryptKey, request.key);
         orbitPostRequestBuilder.AddEncryptedParameter("cryptToken", request.token);
         orbitPostRequestBuilder.AddEncryptedParameter("deviceId", request.deviceid);
         orbitPostRequestBuilder.AddParameter("service", request.service);
         orbitPostRequestBuilder.AddParameter("language", request.language);
         orbitPostRequestBuilder.AddEncryptedParameter("deviceModel", request.model);
         orbitPostRequestBuilder.AddEncryptedParameter("applicationIdentifier", request.appid);
         orbitPostRequestBuilder.AddEncryptedParameter("coverartSize", request.art_width.ToString());
         orbitPostRequestBuilder.AddEncryptedParameter("requestId", str);
         var webRequest = WebRequest.Create(kRequestResultsURL);
         orbitPostRequestBuilder.PopulateWebRequestHeaders(webRequest);
         var requestContext = new RequestContext();
         requestContext.WebRequest     = webRequest;
         requestContext.RequestBuilder = orbitPostRequestBuilder;
         doTimeoutRequest(requestContext, ResultReadCallback, 30000);
     }
     catch (Exception e)
     {
         RecognitionFailed(e);
     }
 }
예제 #2
0
        public int DoRecognition(byte[] audioBuffer, MicrophoneRecordingOutputFormatType formatType)
        {
            shazamRequest = new ShazamRequest();
            var shazamAPIConfig = new ShazamAPIConfig();

            shazamAPIConfig.initKey("20FB1BCBE2C4848F");
            Console.WriteLine(shazamAPIConfig.key);
            shazamRequest.token       = "B540AD35";
            shazamRequest.key         = shazamAPIConfig.key;
            shazamRequest.audioBuffer = audioBuffer;
            shazamRequest.deviceid    = "00000000-0000-0000-0000-000000000000"; // It works
            shazamRequest.service     = "cn=US,cn=V12,cn=SmartClub,cn=ShazamiD,cn=services";
            shazamRequest.language    = "en-US";
            shazamRequest.model       = "Microsoft Windows";
            shazamRequest.appid       = "ShazamId_SmartPhone_Tau__1.3.0";

            if (deviceID != null && deviceID != "")
            {
                shazamRequest.deviceid = deviceID;
            }

            switch (formatType)
            {
            case MicrophoneRecordingOutputFormatType.PCM:
            {
                shazamRequest.filename = "sample.wav";
                break;
            }

            case MicrophoneRecordingOutputFormatType.MP3:
            {
                shazamRequest.filename = "sample.mp3";
                break;
            }

            case MicrophoneRecordingOutputFormatType.SIG:
            {
                shazamRequest.filename = "sample.sig";
                break;
            }
            }

            var request = shazamRequest;

            try
            {
                RaiseOnRecongnitionStateChanged(ShazamRecognitionState.Sending, null);
                var audio                   = request.audioBuffer;
                var audioLength             = audio.Length.ToString();
                var tagDate                 = DateTime.Now.ToUniversalTime().ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss");
                var orbitPostRequestBuilder = new OrbitPostRequestBuilder(encryptKey, request.key);
                orbitPostRequestBuilder.AddEncryptedParameter("cryptToken", request.token);
                orbitPostRequestBuilder.AddEncryptedParameter("deviceId", request.deviceid);
                orbitPostRequestBuilder.AddParameter("service", request.service);
                orbitPostRequestBuilder.AddParameter("language", request.language);
                orbitPostRequestBuilder.AddEncryptedParameter("deviceModel", request.model);
                orbitPostRequestBuilder.AddEncryptedParameter("applicationIdentifier", request.appid);
                orbitPostRequestBuilder.AddEncryptedParameter("tagDate", tagDate);
                orbitPostRequestBuilder.AddEncryptedParameter("sampleBytes", audioLength);
                orbitPostRequestBuilder.AddEncryptedFile("sample", request.filename, audio, audio.Length);
                var webRequest = WebRequest.Create(kDoRecognitionURL);
                orbitPostRequestBuilder.PopulateWebRequestHeaders(webRequest);
                doTimeoutRequest(new RequestContext
                {
                    WebRequest     = webRequest,
                    RequestBuilder = orbitPostRequestBuilder
                }, RecognitionReadCallback, 30000);
            }
            catch (Exception e)
            {
                RecognitionFailed(e);
            }

            return(0);
        }