Skip to content
This repository has been archived by the owner on Jun 13, 2024. It is now read-only.

Commit

Permalink
Microsoft Cognitive Services SDK Release - June 2016
Browse files Browse the repository at this point in the history
  • Loading branch information
yungshinlintw authored and Project Oxford SDK committed Jun 7, 2016
1 parent 3615923 commit b469c42
Show file tree
Hide file tree
Showing 43 changed files with 581 additions and 223 deletions.
21 changes: 16 additions & 5 deletions Emotion/Android/.gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
.gradle
local.properties
.idea/
.idea/libraries
.DS_Store
# Generated files
bin/
gen/
out/
build/

# OS specific files
.DS_Store

# IntelliJ / Android studio configuration files
.idea/
*.iml

# Gradle generated files
.gradle/

# Local config (e.g. sdk path)
local.properties
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ public class Scores {
public double neutral;
public double sadness;
public double surprise;

public List<Map.Entry<String, Double>> ToRankedList(Order order)
{

// create a Map to store each entry
Map<String, Double> collection = new HashMap<String, Double>() ;

// add each entry with its own key and value
collection.put("ANGER",anger);
collection.put("CONTEMPT",contempt);
Expand All @@ -68,9 +68,9 @@ public List<Map.Entry<String, Double>> ToRankedList(Order order)

// create a list with the entries
List<Map.Entry<String, Double>> list = new ArrayList<Map.Entry<String, Double>>(collection.entrySet());

// we are going to create a comparator according to the value of the enum order
switch (order)
switch (order)
{
case ASCENDING:
Collections.sort(list, new Comparator<Map.Entry<String, Double>>() {
Expand All @@ -81,22 +81,22 @@ public int compare(Entry<String, Double> first, Entry<String, Double> second) {
}
});
break;

case DESCENDING:
// for ordering descending we should create a reverse order comparator
// for ordering descending we should create a reverse order comparator
Collections.sort(list, Collections.reverseOrder(new Comparator<Map.Entry<String, Double>>() {
@Override
public int compare(Entry<String, Double> first, Entry<String, Double> second) {
return first.getValue().compareTo(second.getValue());
}
}));
}));
break;

default:
break;
}

return list;

}
}
6 changes: 3 additions & 3 deletions Emotion/Android/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ The client library
==================

The Emotion API client library is a thin Java client wrapper for Microsoft Cognitive Services (formerly Project Oxford)
Emotion REST APIs.
Emotion REST APIs.

The easiest way to consume the client library is to add com.microsoft.projectoxford.emotion package from Maven Central Repository.

Expand Down Expand Up @@ -31,7 +31,7 @@ To do add the client library dependency from Android Studio:
6. Type "com.microsoft.projectoxford" and hit the search icon from "Choose Library Dependency" dialog
7. Pick the Project Oxford client library that you intend to use.
8. Click "OK" to add the new dependency

Order expressions
============

Expand All @@ -45,7 +45,7 @@ List<Map.Entry<String, Double>> collection = scores.ToRankedList(Order.ASCENDING
DESCENDING
```
List<Map.Entry<String, Double>> collection = scores.ToRankedList(Order.DESCENDING);
```

The sample
Expand Down
7 changes: 0 additions & 7 deletions Emotion/Android/Sample/.gitignore

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,9 @@ protected void onPostExecute(List<RecognizeResult> result) {
mEditText.append("No emotion detected :(");
} else {
Integer count = 0;
Canvas faceCanvas = new Canvas(mBitmap);
// Covert bitmap to a mutable bitmap by copying it
Bitmap bitmapCopy = mBitmap.copy(Bitmap.Config.ARGB_8888, true);
Canvas faceCanvas = new Canvas(bitmapCopy);
faceCanvas.drawBitmap(mBitmap, 0, 0, null);
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setStyle(Paint.Style.STROKE);
Expand Down
2 changes: 1 addition & 1 deletion Emotion/Android/Sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
classpath 'com.android.tools.build:gradle:2.1.0'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Apr 10 15:27:10 PDT 2013
#Fri Jun 03 14:18:22 PDT 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
71 changes: 28 additions & 43 deletions Emotion/Python/Jupyter Notebook/Emotion Analysis Example.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Emotion/Windows/ClientLibrary/Contract/Scores.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public class Scores
///
/// </summary>
public float Surprise { get; set; }

/// <summary>
/// Create a sorted key-value pair of emotions and the corresponding scores, sorted from highest score on down.
/// To make the ordering stable, the score is the primary key, and the name is the secondary key.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.ProjectOxford.Common, Version=1.0.250.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<Reference Include="Microsoft.ProjectOxford.Common, Version=1.0.250, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.ProjectOxford.Common.1.0.250\lib\portable-net45+win+wpa81+wp80+MonoAndroid10+xamarinios10+MonoTouch10\Microsoft.ProjectOxford.Common.dll</HintPath>
<Private>True</Private>
</Reference>
Expand Down
18 changes: 18 additions & 0 deletions Face/Android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated files
bin/
gen/
out/
build/

# OS specific files
.DS_Store

# IntelliJ / Android studio configuration files
.idea/
*.iml

# Gradle generated files
.gradle/

# Local config (e.g. sdk path)
local.properties
2 changes: 1 addition & 1 deletion Face/Android/Sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
classpath 'com.android.tools.build:gradle:2.1.0'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
4 changes: 2 additions & 2 deletions Face/Android/Sample/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Apr 10 15:27:10 PDT 2013
#Mon Jun 06 16:40:57 PDT 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
63 changes: 23 additions & 40 deletions Face/Python/Jupyter Notebook/Face Detection Example.ipynb

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ def get_all_profiles(self):
return [IdentificationProfile.IdentificationProfile(profiles_raw[i])
for i in range(0, len(profiles_raw))]
else:
raise Exception('Error getting all profiles: ' + res.reason)
reason = res.reason if not message else message
raise Exception('Error getting all profiles: ' + reason)
except:
logging.error('Error getting all profiles.')
raise
Expand All @@ -112,8 +113,8 @@ def create_profile(self, locale):
# Parse the response body
return ProfileCreationResponse.ProfileCreationResponse(json.loads(message))
else:
message = res.read().decode('utf-8')
raise Exception('Error creating profile: ' + res.reason)
reason = res.reason if not message else message
raise Exception('Error creating profile: ' + reason)
except:
logging.error('Error creating profile.')
raise
Expand All @@ -131,6 +132,7 @@ def enroll_profile(self, profile_id, file_path):
request_url = '{0}/{1}/enroll'.format(
self._IDENTIFICATION_PROFILES_URI,
urllib.parse.quote(profile_id))
print(request_url);

# Prepare the body of the message
with open(file_path, 'rb') as body:
Expand All @@ -151,7 +153,8 @@ def enroll_profile(self, profile_id, file_path):
return EnrollmentResponse.EnrollmentResponse(
self._poll_operation(operation_url))
else:
raise Exception('Error enrolling profile: ' + res.reason)
reason = res.reason if not message else message
raise Exception('Error enrolling profile: ' + reason)
except:
logging.error('Error enrolling profile.')
raise
Expand Down Expand Up @@ -192,7 +195,8 @@ def identify_file(self, file_path, test_profile_ids):
return IdentificationResponse.IdentificationResponse(
self._poll_operation(operation_url))
else:
raise Exception('Error identifying file: ' + res.reason)
reason = res.reason if not message else message
raise Exception('Error identifying file: ' + reason)
except:
logging.error('Error identifying file.')
raise
Expand All @@ -216,7 +220,8 @@ def _poll_operation(self, operation_url):
self._JSON_CONTENT_HEADER_VALUE)

if res.status != self._STATUS_OK:
raise Exception('Operation Error: ' + res.reason)
reason = res.reason if not message else message
raise Exception('Operation Error: ' + reason)

# Parse the response body
operation_response = json.loads(message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ def get_all_profiles(self):
return [VerificationProfile.VerificationProfile(profiles_raw[i])
for i in range(0, len(profiles_raw))]
else:
raise Exception('Error getting all profiles: ' + res.reason)
reason = reason if not message else message
raise Exception('Error getting all profiles: ' + reason)
except:
logging.error('Error getting all profiles.')
raise
Expand All @@ -72,8 +73,8 @@ def create_profile(self, locale):
# Parse the response body
return ProfileCreationResponse.ProfileCreationResponse(json.loads(message))
else:
message = res.read().decode('utf-8')
raise Exception('Error creating profile: ' + res.reason)
reason = res.reason if not message else message
raise Exception('Error creating profile: ' + reason)
except:
logging.error('Error creating profile.')
raise
Expand Down Expand Up @@ -106,7 +107,8 @@ def enroll_profile(self, profile_id, file_path):
# Parse the response body
return EnrollmentResponse.EnrollmentResponse(json.loads(message))
else:
raise Exception('Error enrolling profile: ' + res.reason)
reason = res.reason if not message else message
raise Exception('Error enrolling profile: ' + reason)
except:
logging.error('Error enrolling profile.')
raise
Expand Down Expand Up @@ -138,7 +140,8 @@ def verify_file(self, file_path, profile_id):
# Parse the response body
return VerificationResponse.VerificationResponse(json.loads(message))
else:
raise Exception('Error verifying audio from file: ' + res.reason)
reason = res.reason if not message else message
raise Exception('Error verifying audio from file: ' + reason)
except:
logging.error('Error performing verification.')
raise
Expand Down
3 changes: 2 additions & 1 deletion Speech/Speech.JS/index.htm
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
</head>
<body style="font-family:'Segoe UI', Tahoma, Geneva, Verdana, sans-serif">
<table width="100%">
<tr><td/><td><h1>Speech.JS</h1><h2>Microsoft Cognitive Services</h2></td></tr>
<tr>
<td align="right"/>
<td><input id="useMic" type="checkbox">Use Microphone</td>
Expand All @@ -156,7 +157,7 @@
</td>
</tr>
<tr>
<td align="right">Oxford Key:</td>
<td align="right"><A href="https://www.microsoft.com/cognitive-services/en-us/sign-up" target="_blank">Subscription</A>:</td>
<td><input id="oxfordkey" type="text" size="40"></td>
</tr>
<tr>
Expand Down
46 changes: 19 additions & 27 deletions Speech/Speech.JS/speech.1.0.0.js
Original file line number Diff line number Diff line change
Expand Up @@ -509,9 +509,9 @@ var Bing;
Bing._window.msSpeechButton.audioprocess(e);
}
};
source.connect(destination);
cu.connect(source);
destination.connect(source.context.destination);
source.connect(destination);
return destination;
};
Object.defineProperty(Speech.prototype, "isMicSource", {
Expand Down Expand Up @@ -802,33 +802,25 @@ var Bing;
}
LuisClient.kServiceUrl = "https://api.projectoxford.ai/luis/v1/application?subscription-key=";
LuisClient.prototype.getIntent = function (text) {
var _this = this;
var task = new Task();
var request = new XMLHttpRequest();
this._auth.authenticate(this._prefs.clientId, this._prefs.clientSecret).done(function (token) {
if (!token) {
request.open('GET', [
LuisClient.kServiceUrl,
this._prefs.luisSubscriptionId,
"&id=",
this._prefs.luisAppId,
"&q=",
text
].join(""), true);
request.onload = function () {
if (request.readyState == 4 && request.status === 200) {
var response = handleJSONWebResponse(request);
task.resolve(request.response);
} else {
task.resolve(null);
return;
}
request.open('GET', [
LuisClient.kServiceUrl,
_this._prefs.luisSubscriptionId,
"&id=",
_this._prefs.luisAppId,
"&q=",
text
].join(""), true);
request.setRequestHeader("Authorization", token);
request.onload = function () {
if (request.readyState == 4 && request.status === 200) {
var response = handleJSONWebResponse(request);
task.resolve(request.response);
} else {
task.resolve(null);
}
};
request.send();
});
};
request.send();
return task;
};
return LuisClient;
Expand Down Expand Up @@ -1384,12 +1376,12 @@ var Bing;
};
WebAudioSource.prototype.onBufferLoaded = function () {
var _this = this;
this._bufferSource.connect(this._destination);
this._bufferSource.start(0);
this._started = true;
this._bufferSource.onended = function () {
_this.handleEnd();
};
this._bufferSource.connect(this._destination);
this._bufferSource.start(0);
this._started = true;
};
WebAudioSource.prototype.toString = function () {
return this._url;
Expand Down
2 changes: 1 addition & 1 deletion Speech/Speech.JS/speech.1.0.0.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit b469c42

Please sign in to comment.