Azure: Why is JavaScript STT-SDK from a default microphone just for PC, but not for mobile phones? - microsoft-cognitive

The Azure JavaScript-STT-SDK works well on PC, but it does not work on mobile phones.
const audioConfig = AudioConfig.fromDefaultMicrophoneInput()
//code
speech() {
let that = this;
const speechConfig = SpeechConfig.fromSubscription(
"*******",
"*******"
);
speechConfig.speechRecognitionLanguage = "zh-CN";
const audioConfig = AudioConfig.fromDefaultMicrophoneInput();
const recognizer = new SpeechRecognizer(speechConfig, audioConfig);
recognizer.start;
recognizer.recognizeOnceAsync(result => {
switch (result.reason) {
case ResultReason.RecognizedSpeech:
console.log(`RECOGNIZED: Text=${result.text}`);
that.inputMsg = result.text;
console.log(" Intent not recognized.");
break;
case ResultReason.NoMatch:
console.log("NOMATCH: Speech could not be recognized.");
that.tts("没有听到您说话喔~");
break;
case ResultReason.Canceled:
const cancellation = CancellationDetails.fromResult(result);
console.log(`CANCELED: Reason=${cancellation.reason}`);
if (cancellation.reason == CancellationReason.Error) {
console.log(`CANCELED: ErrorCode=${cancellation.ErrorCode}`);
console.log(
`CANCELED: ErrorDetails=${cancellation.errorDetails}`
);
console.log("CANCELED: Did you update the subscription info?");
}
break;
}
});
},

For now, to use it in microphone you need to use the browser SDK, for a sample you could refer to this doc: Recognize speech from a microphone.
Node: when you test with the browser, it doesn't work on the Safari browser. On Safari, the sample web page needs to be hosted on a web server; Safari doesn't allow websites loaded from a local file to use the microphone.

Related

Setting Segment ajs_anonymous_id from SSR on client if user doesn't have cookie with Next.js App?

Anyone set the ajs_anonymous_id in SSR (nextjs) if it doesn't currently exist on client?
I have a need to "read" the ajs_anonymous_id (Segment analytics) cookie during a SSR rendering in Next.Js, but of course there are instances when that cookie does not exist yet ie...person hasn't visited my site before and thus never go it... BUT, since i need in SSR side..... I was hoping there is a process I can "set it" on the server side so that I can use it, THEN have it on the client too... so..
client visits page
Has ajs_anonymous_id cookie, cool, use it and do some display things....
Does not have ajs_anonymous_id, I seed the ajs_anonymous_id (drop a cookie) and then do some display things.
pages loads.. My analytics file (that loads on the font end thru a containe) sees there is an already ajs_anonymous_id cookie, cool.
Anyone have an example of this or how to achieve it?
yeah - there seems to be a package and method just for this.
import Analytics from 'analytics-node'
// if no anonymousId, send a randomly generated one
// otherwise grab existing to include in call to segment
let anonymousId
if (cookies.ajs_anonymous_id) {
anonymousId = cookies.ajs_anonymous_id
} else {
anonymousId = = uuid.v4()
res.cookie('ajs_anonymous_id', anonymousId )
}
for the full example, i'd refer to their docs:
https://segment.com/docs/guides/how-to-guides/collect-pageviews-serverside/
For NextJS, I expect you have to move away from their server default implementation and build a wrapper to allow you to add this type of middleware.
const express = require('express');
const bodyParser = require('body-parser');
const next = require('next');
const host = process.env.LOCAL_ADDRESS || '0.0.0.0';
const port = parseInt(process.env.NODE_PORT, 10) || 3000;
const dev = process.env.NODE_ENV !== 'production';
const app = next({ dev, dir: 'app' });
const handle = app.getRequestHandler();
app.prepare().then(() => {
const server = express();
server.use(bodyParser.urlencoded({ extended: false }));
server.set('trust proxy', true);
server.use(customMiddleware);
server.all('*', (req, ...args) => {
// Log the request only if we need to (we don't log all static asset requests)
if (req.log) {
req.log.info('incoming request');
}
return handle(req, ...args);
});
server.listen(port, host, (err) => {
if (err) throw err;
console.log(`> Ready on http://${host}:${port}`);
});
});
then start the app with node app/server
Hope that helps to get you started!

Xamarin.Forms AVPlayer exit fullscreen from method

I have a Xamarin application which plays a video for 30 seconds and then shows a dialog. The user can continue to watch (dismiss the dialog) or click an action in the dialog (which then should close full-screen and navigate elsewhere in the app).
I have this working on the simulator. However, when I run the following code on an real iOS device, the app crashes without any stacktrace.
ViewModel.cs
var openLink = await _userDialogs.ConfirmAsync("...", cancelText: "Dismiss", okText: "Yes");
if (openLink)
{
await _navigationService.Close(scope);
MessagingCenter.Send(Application.Current, "CloseFullscreen");
}
VideoRenderer.cs
_playerViewController = new AVPlayerViewController()
{
ExitsFullScreenWhenPlaybackEnds = true
};
player = new AVPlayer();
_playerViewController.Player = player;
...
SetNativeControl(_playerViewController.View);
MessagingCenter.Subscribe<Xamarin.Forms.Application>(this, "CloseFullscreen", (app) =>
{
BeginInvokeOnMainThread(() =>
{
var selectorName = "exitFullScreenAnimated:completionHandler:";
var selector = new ObjCRuntime.Selector(selectorName);
if (_playerViewController.RespondsToSelector(selector))
_playerViewController.PerformSelector(selector, NSObject.FromObject(true), 0);
});
});
Please note that I am not using the CrossMediaManager plugin due to this bug: https://github.com/Baseflow/XamarinMediaManager/issues/629

OneSignal Wordpress Notifications not opening in App

I am struggeling to find a solution for my Cordova Native App.
I am using OneSignal to send out push notifications once a new Article has been published. The push notifications are working fine but the moment I click onto the notification the normal browser opens and not the app.
NB: When I send a test notification through OneSignal and click on it the App opens.
My code just does not want to work with Wordpress articles.
Here's the code which I am using in my index.js
document.addEventListener('deviceready', function () {
// Enable to debug issues.
// window.plugins.OneSignal.setLogLevel({logLevel: 4, visualLevel: 4});
var notificationOpenedCallback = function(jsonData) {
var additionalData = jsonData.notification.payload.additionalData
if (additionalData && additionalData.myKey)
// Not familiar with Cordova, $state may or may not be available here
$state.go('app.post', {'postId': + additionalData.myKey});
};
window.plugins.OneSignal
.startInit("0b8b7e69-1649-4616-XXXXXXX")
.handleNotificationOpened(notificationOpenedCallback)
.endInit();
// Call syncHashedEmail anywhere in your app if you have the user's email.
// This improves the effectiveness of OneSignal's "best-time" notification scheduling feature.
// window.plugins.OneSignal.syncHashedEmail(userEmail);
}, false);
Has anyone any idea what is possibly wrong with my code?
All you need to put all codes under plugin check on device ready function and make sure you parse the data into array object because they sending raw looks like -
if (window.plugins && window.plugins.OneSignal) {
.startInit(your_appid, your_google_project)
.inFocusDisplaying(window.plugins.OneSignal.OSInFocusDisplayOption.Notification)
.handleNotificationOpened(function(jsonData) {
if (device.platform =="Android") {
var addData = JSON.parse(jsonData.result.notification.payload.additionalData);
} else {
var addData = jsonData.result.notification.payload.additionalData;
}
if (addData != undefined) {
if (addData.posts != undefined) {
var postID = Number(addData.posts);
$state.go('app.post', {postId: postID });
}
}
})
.endInit();
}
Note: According to there doc they update the additional data tree to
result.notification.payload.additionalData
Not notification.payload.additionalData
Put this function on your wordpress theme function.php and make sure you have disable the option "Send notifications additionally to iOS & Android platforms". on WordPress plugin page.
add_filter('onesignal_send_notification', 'onesignal_send_notification_filter', 10, 4);
function onesignal_send_notification_filter($fields, $new_status, $old_status, $post)
{
$postID = $post->id;
$fields['isAndroid'] = true;
$fields['isIos'] = true;
$fields['isAnyWeb'] = false;
$fields['isChrome'] = false;
$fields['data'] = array(
"posts" => $postID
);
return $fields;
}
Just leaving this here, in case someone else can make use of it.
add_filter('onesignal_send_notification', 'onesignal_send_notication_filter_push', 10, 4);
function onesignal_send_notication_filter_push($fields, $new_status, $old_status, $post)
{
$fields['isAndroid'] = true;
$fields['isIos'] = true;
$fields['isAnyWeb'] = false;
$fields['isChrome'] = false;
// overwrite http url with app_url so push notifications opens app instead of phone browser.
$fields['url'] = $fields['app_url'];
return $fields;
}

push notification does not work for ios and azure with specific token

We are using Visual Studio to create an Apache Cordova app that is connected to an Azure Mobile Service . We are using the Cordova Push Plugin to receive Notifications in our app. We have created a JavaScript method in the Azure Mobile Service to send the notifications, this method is triggered by a scheduler. Please note that the intention is to send each Notification to a particular device.
The notifications work perfectly for Android devices but not for the iOS devices.
In iOS the notification is not received however the method in Azure Mobile Service always returns “Success”.
If we set the Device Token to "Null" , then it works for iOS devices (but sends to all devices not just one).
Could anyone please help us to resolve this issue?
this is Push.Send() method in Azure
push.send(result.DeviceID, payload, {
success: function(pushResponse){
//console.log("Sent push:", pushResponse);
//update notification sent time-start
var sqlUpdate = '';
mssql.query(sqlUpdate, {
success: function(results)
{
//response.json(statusCodes.OK, results);
},
error : function()
{
//response.send(statusCodes.INTERNAL_SERVER_ERROR);
}
})
//update notification sent time-end
},
error: function (pushResponse) {
//console.log("Error Sending push:", pushResponse);
}
});
and this is my App registration Method in the app
var pushNotification = window.plugins.pushNotification;
//alert("device.platform" + device.platform);
// Platform-specific registrations.
if (device.platform == 'android' || device.platform == 'Android') {
alert("device.platform : Android ");
// Register with GCM for Android apps.
pushNotification.register(
app.successHandler, app.errorHandler,
{
"senderID": GCM_SENDER_ID,
"ecb": "app.onNotificationGCM"
});
} else if (device.platform === 'iOS') {
// Register with APNS for iOS apps.
alert("device.platform : iOS ");
pushNotification.register(
app.tokenHandler,
app.errorHandler, {
"badge":"true",
"sound":"true",
"alert":"true",
"ecb": "app.onNotificationAPN"
});
}
else if(device.platform === "Win32NT"){
// Register with MPNS for WP8 apps.
alert("Device platform Windows")
pushNotification.register(
app.channelHandler,
app.errorHandler,
{
"channelName": "MyPushChannel",
"ecb": "app.onNotificationWP8",
"uccb": "app.channelHandler",
"errcb": "app.ErrorHandler"
});
}
// #endregion notifications-registration

navigator.connection.type not working even if device is ready *or* device is never ready

I'm trying to make a simple app with Phonegap, compiled with Adobe Phonegap builder. I've found and used the well documented example for using navigator.connection.type which is below, and to which I've added another line, to generate an alert box when the device is ready. It doesn't even get that far. I've had it at some points show that endless spinning circle, by moving this code from the head to the body of the page, but that is no help in the end. Testing on iOs and Android devices gives the same result, and the config.xml does include:-
<plugin name="NetworkStatus" value="CDVConnection" />
<plugin name="NetworkStatus" value="org.apache.cordova.NetworkManager" />
Any help greatly appreciated.
// Wait for Cordova to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// Cordova is loaded and it is now safe to make calls Cordova methods
//
function onDeviceReady() {
alert('Device is ready');
checkConnection();
}
function checkConnection() {
var networkState = navigator.connection.type;
var states = {};
states[Connection.UNKNOWN] = 'Unknown connection';
states[Connection.ETHERNET] = 'Ethernet connection';
states[Connection.WIFI] = 'WiFi connection';
states[Connection.CELL_2G] = 'Cell 2G connection';
states[Connection.CELL_3G] = 'Cell 3G connection';
states[Connection.CELL_4G] = 'Cell 4G connection';
states[Connection.CELL] = 'Cell generic connection';
states[Connection.NONE] = 'No network connection';
alert('Connection type: ' + states[networkState]);
}
</script>
You should also wait until all your scripts are loaded. Wrap everything in a onBodyLoad like so:
function onBodyLoad() {
// these are useful later in the app, might as well set early
window.isRipple = (window.tinyHippos != null);
window.isPhoneGap = /^file:\/{3}[^\/]/i.test(window.location.href);
window.isIOS = !window.isRipple && navigator.userAgent.match(/(ios|iphone|ipod|ipad)/gi) != null;
window.isAndroid = !window.isRipple && navigator.userAgent.match(/(android)/gi) != null;
// stuff I use for debugging in chrome
if (window.isPhoneGap) {
document.addEventListener("deviceready", onDeviceReady, false);
} else {
onDeviceReady();
}
}
And add to your body tag:
<body onload="onBodyLoad()">
And the rest of my code for additional references:
function checkOffLine(minutes) {
if (window.lastCheckTime == null) {
window.lastCheckTime = 0;
}
var currentTime = (new Date()).getTime();
if (currentTime < (window.lastCheckTime + minutes * 60000)) return;
window.lastCheckTime = currentTime;
// ios does not allow you to exit the application so just warn
// ios also require you to warn or your app get rejected
if (window.isIOS) {
navigator.notification.alert('This application may not function properly without an internet connection.');
} else {
navigator.notification.confirm(
'This application may not function properly without an internet connection. Continue working offline?', // message
function(button) // callback to invoke with index of button pressed
{
if (button == 1) {
navigator.app.exitApp();
}
},
'Warning', // title
'Exit,Continue' // buttonLabels
);
}
}
function checkConnection() {
// your check connection type code here or just use navigator.onLine
if (!navigator.onLine) {
// don't be annoying, only confirm for once every every 5 minutes
checkOffLine(5);
}
}
// initial phonegap deviceready handler
function onDeviceReady() {
console.log('Application started');
angular.bootstrap(document, ['assetsApp']);
if (window.isPhoneGap) {
document.addEventListener("offline", checkConnection, false);
checkConnection();
}
};
function onBodyLoad() {
// these are useful later in the app, might as well set early
window.isRipple = (window.tinyHippos != null);
window.isPhoneGap = /^file:\/{3}[^\/]/i.test(window.location.href);
window.isIOS = !window.isRipple && navigator.userAgent.match(/(ios|iphone|ipod|ipad)/gi) != null;
window.isAndroid = !window.isRipple && navigator.userAgent.match(/(android)/gi) != null;
// stuff I use for debugging in chrome
if (window.isPhoneGap) {
document.addEventListener("deviceready", onDeviceReady, false);
} else {
onDeviceReady();
}
}
I had the same issue and found I had to run "cordova build" and then the status was returned correctly.
BEWARE
When I run cordova build, it appears to take everything in my ~/app/www directory and overried everything in app/platforms/android/assets/www/
My "install process" is as follows:
cordova create app com.app "App"
cd app
cordova platform add android
cordova plugin add org.apache.cordova.network-information
cordova plugin add org.apache.cordova.camera
cordova plugin add org.apache.cordova.geolocation
cordova build
I can then do code changes in app/www and when happy, 'deploy' it using 'cordova build' (which seems to always copy the files to app/platforms/android/assets/www/.
If I add another plugin using: (for example)
cordova plugin add org.apache.cordova.file
then I need to run
cordova build
to have it work.
I hope this helps
(I am using cordova 3.3.1-0.1.2 )

Resources