I am trying to play/push a MP4 to my receiver app on my whitelisted device.
I am able to launch my receiver app (an web page with a video tag).
Once I launch my receiver app, then from my Sender app (another web page) I do this:
new MediaLoadRequest(url);
cast_api.loadMedia(activityId, mediaRequest, callback);
My receiver looks like this:
initReceiver = function(){
_remoteMedia.setMediaElement(videoSurface);
_remoteMedia.onOpen = mediaOnOpen;
_remoteMedia.onLoad = mediaOnLoad;
_remoteMedia.onLoadMetadataError = mediaMetaDataError;
_remoteMedia.onMetadataLoaded = mediaMetaDataLoaded;
_receiver.start();
mediaOnLoad = function (channel, message){
_remoteMedia.load(channel, message);
_remoteMedia.sendSuccessResponse(channel,message);
}
mediaMetaDataLoaded = function (channel, message){
console.log("mediaMetaDataLoaded", message);
}
mediaMetaDataError = function (channel,message){
console.log("mediaMetaDataError", message);
}
mediaOnOpen = function (event){
console.log("mediaOnOpen", event);
}
On the console output the last message I see is this, after the code hits _remoteMedia.load:
[ 41.321s] [cast.receiver.RemoteMedia] loading media
and nothing happens after that. The media is a valid URL from my DropBox...an MP4.
Any ideas what I am doing wrong here?
Thanks!
You actually can just use our default Receiver and it will play your content. No need to provide all those extra functions.
Related
I am going to develop a simple web based Speech to Text project. Develop with NodeJS, ws (WebSocket), and Google's Speech to Text API.
However, I have no luck to get the transcript from Google's Speech to Text API.
Below are my server side codes (server.js):
ws.on('message', function (message) {
if (typeof message === 'string') {
if(message == "connected") {
console.log(`Web browser connected postback.`);
}
}
else {
if (recognizeStream !== null) {
const buffer = new Int16Array(message, 0, Math.floor(message.byteLength / 2));
recognizeStream.write(buffer);
}
}
});
Below are my client side codes (ws.js):
function recorderProcess(e) {
var floatSamples = e.inputBuffer.getChannelData(0);
const ConversionFactor = 2 ** (16 - 1) - 1;
var floatSamples16 = Int16Array.from(floatSamples.map(n => n * ConversionFactor));
ws.send(floatSamples16);
}
function successCallback(stream) {
window.stream = stream;
var audioContext = window.AudioContext;
var context = new audioContext();
var audioInput = context.createMediaStreamSource(stream);
var recorder = context.createScriptProcessor(2048, 1, 1);
recorder.onaudioprocess = recorderProcess;
audioInput.connect(recorder);
recorder.connect(context.destination);
}
When I run the project, and open http://localhost/ in my browser, trying to speaking some sentences to the microphone. Unfortunately, there are no transcription returned, and no error messages returned in NodeJS console.
When I check the status in Google Cloud Console, it only display a 499 code in the dashboard.
Many thanks for helping!
I think the issue could be related to the stream process. Maybe some streaming process is stopped before the end of an operation. My suggestion is to review the callbacks in the JasvaScript code in order to find some “broken" promises.
Also, maybe its obvious but there is a different doc for audios than more than a minute:
https://cloud.google.com/speech-to-text/docs/async-recognize
CANCELLED - The operation was cancelled, typically by the caller.
HTTP Mapping: 499 Client Closed Request
Since the error message, this also could be related to the asynchronous and multithread features of node js.
Hope this works!
I have used Microsoft Bot Framework to create a bot for the client side. i.e. called WebChat. I have also added Speech SpeechRecognizer. However, I am trying to trigger a mic when a phrase is recited.
I couldn't find a function in Microsoft that does this. So I added my own speech recognizer that is called every second and once the phrase is called I want to call the mic function from the Cognitive Services.
How Can I achieve this?
I have got the speech recognizer from here
And the one I have written to identify a phrase is this:
function startDictation() {
if (window.hasOwnProperty('webkitSpeechRecognition')) {
var recognition = new webkitSpeechRecognition();
recognition.continuous = false;
recognition.interimResults = false;
recognition.lang = "en-US";
recognition.start();
recognition.onresult = function (e) {
var foundText = e.results[0][0].transcript;
console.log(foundText);
if (foundText == "hello hello") {
console.log("found text");
//call cognitive service mic function
recognition.stop();
}
else {
console.log("text not found");
recognition.stop();
startDictation();
}
};
recognition.onerror = function (e) {
console.log("found error", e);
recognition.stop();
}
}
}
Do let me know if any information is missing or miss-leading.
For more:
I tried to leverage startRecognizing() function in SpeechRecognizer class at https://github.com/Microsoft/BotFramework-WebChat/blob/master/src/CognitiveServices/SpeechRecognition.ts#L72 to trigger the recognize functionality. However, I found that only if I have click the mic item, then I could use startRecognizing() function to recognize the voice.
There is a trick workaround you can try to use at present:
I inspected the mic item, and try to triiger its click event in js, which worked exactly to recognize my speech.
You can try to use following js code snippet with jQuery:
$('.wc-mic').trigger("click")
Hope it helps.
I am using the Slack RTM node client and having a bit of an issue with DM's. Say a user joins the channel who has never DM'ed the bot before, the user types a command in the channel that the bot usually will respond to and by default the bot responds in a private message to the user. However, the bot cannot do this because the dataStore does not contain any DM data for this user. Code sample below...
rtm.on(RTM_EVENTS.MESSAGE, function (message) {
user = rtm.getUserById(message.user);
console.log(user); // It gets the user object fine
dm = rtm.getDMByName(user.name);
console.log(dm); // This is always undefined unless the user has DM'ed the bot previously
});
Is there a way around this? I can't seem to find anything in the docs or code to suggest there might be.
You can use the im.open method of the web API. Here's roughly how you'd do it with #slack/client (untested, apologies in advance!):
var webClient = new WebClient(token);
...
rtm.on(RTM_EVENTS.MESSAGE, function (message) {
var dm = rtm.getDMById(message.user);
if (dm) {
console.log(`Already open IM: ${dm}`);
// send a message or whatever you want to do here
} else {
webClient.im.open(message.user, function (err, result) {
var dm = result.channel.id;
console.log(`Newly opened IM: ${dm}`);
// send a message or whatever you want to do here
});
}
});
I am currently using PubNub SDK for chatting in website and iPhone. Now i want to implement functionality like i want to send message from iPhone to web-end once user sends a message from iPhone to web-end ( user will be notified ).
Now the issue is when initially user1 sends message from iPhone to webend i am not getting notification.
on first message i am not getting notification.
code is somewhat like this
var socket = new WebSocket("Pubnub + channel1id";
var chat_socket = new WebSocket("Pubnub + channel2id";
socket.onmessage = function (evt)
{
//Here i implemeted our notification functionality.
}
chat_socket.onmessage = function (evt)
{
//Here i implemeted our notification functionality.
}
on second message i am getting object on .onmessage but not for first.
I am attempting to listen to a particular event type regardless of the channel it was triggered in. My understanding of the docs (http://pusher.com/docs/client_api_guide/client_events#bind-events/lang=js) was that I can do so by calling the bind method on the pusher instance rather than on a channel instance. Here is my code:
var pusher = new Pusher('MYSECRETAPPKEY', {'encrypted':true}); // Replace with your app key
var eventName = 'new-comment';
var callback = function(data) {
// add comment into page
console.log(data);
};
pusher.bind(eventName, callback);
I then used the Event Creator tool in my account portal to generate an event. I used a random channel name, set the Event to "new-comment" and just put in some random piece of text into the Event Data. But, I am getting nothing appearing in my Console.
I am using https://d3dy5gmtp8yhk7.cloudfront.net/2.1/pusher.min.js, and performing this test in the latest Chrome.
What am I missing?
Thanks!
Shaheeb R.
Pusher will only send events to the client if that client has subscribed to the channel. So, the first thing you need to do is subscribe the channel. Binding to the event on the client:
pusher.bind('event_name', function( data ) {
// handle update
} );
This is also known as "global event binding".
I've tested this using this code and it does work:
http://jsbin.com/AROvEDO/1/edit
For completeness, here's the code:
var pusher = new Pusher('APP_KEY');
var channel = pusher.subscribe('test_channel');
pusher.bind('my_event', function(data) {
alert(data.message);
});