예제 #1
0
 private void DoGetResult(ulong requestId)
 {
     try
     {
         RaiseOnRecongnitionStateChanged(ShazamRecognitionState.Matching, null);
         shazamRequest.requestId = requestId;
         shazamRequest.art_width = 520;
         ShazamRequest           request = shazamRequest;
         string                  str     = request.requestId.ToString();
         OrbitPostRequestBuilder 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);
         WebRequest webRequest = WebRequest.Create(kRequestResultsURL);
         orbitPostRequestBuilder.PopulateWebRequestHeaders(webRequest);
         RequestContext requestContext = new RequestContext();
         requestContext.WebRequest     = webRequest;
         requestContext.RequestBuilder = orbitPostRequestBuilder;
         doTimeoutRequest(requestContext, new AsyncCallback(ResultReadCallback), 30000);
     }
     catch (Exception e)
     {
         RecognitionFailed(e);
     }
 }
예제 #2
0
        public int DoRecognition(byte[] audioBuffer, MicrophoneRecordingOutputFormatType formatType)
        {
            shazamRequest = new ShazamRequest();
            ShazamAPIConfig 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;
            }
            }

            ShazamRequest request = shazamRequest;

            try
            {
                RaiseOnRecongnitionStateChanged(ShazamRecognitionState.Sending, null);
                byte[] audio       = request.audioBuffer;
                string audioLength = audio.Length.ToString();
                string tagDate     = DateTime.Now.ToUniversalTime().ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss");
                OrbitPostRequestBuilder 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);
                WebRequest webRequest = WebRequest.Create(kDoRecognitionURL);
                orbitPostRequestBuilder.PopulateWebRequestHeaders(webRequest);
                doTimeoutRequest(new RequestContext
                {
                    WebRequest     = webRequest,
                    RequestBuilder = orbitPostRequestBuilder
                }, new AsyncCallback(RecognitionReadCallback), 30000);
            }
            catch (Exception e)
            {
                RecognitionFailed(e);
            }
            return(0);
        }