okay, thx for your effort.
Short test shows I can download the mp3 from the web server.
-
Let Google Home say "Hello"!
-
I tried it on my good old ubuntu notebook. Same result. Could it be a missing dependency?
-
Could you try the following code, and see what the log says?
var fs = require('fs'); var http = require('http'); http.createServer(function (req, res) { fs.readFile(__dirname + req.url, function (err,data) { if (err) { res.writeHead(404); res.end(JSON.stringify(err)); return; } res.writeHead(200); res.end(data); }); }).listen(8088);
-
Hi, you can skip the test above with only the http part. There could be a problem with the http server not closing right.
So a new version with extra handling for the http server partconst ChromecastAPI = require('chromecast-api') var fs = require('fs'); var http = require('http'); server = http.createServer(function (req, res) { fs.readFile(__dirname + req.url, function (err,data) { if (err) { res.writeHead(404); res.end(JSON.stringify(err)); return; } res.writeHead(200); res.end(data); }); }).listen(8088); server.on('clientError', (err, socket) => { socket.end('HTTP/1.1 400 Bad Request\r\n\r\n'); }); var filename = process.argv[2]; var gaDevice = process.argv[3]; if (filename == null) { console.log('Filename missing'); process.exit(); } if (gaDevice == null) { console.log('GA name missing'); process.exit(); } const baseUrl = 'http://192.168.x.x:8088/'; const media = { url : baseUrl + filename } var device const client = new ChromecastAPI() client.on('device', function (_device) { device = _device console.log('Device',device.friendlyName,'found'); if (gaDevice == device.friendlyName) { device.play(media, function (err) { if (!err) console.log('Playing',media.url,'on your chromecast'); if (err) console.log('error: ', err); }) } }); client.on('error', function (err) { if (err) console.log('error: ', err); }); terminate = function() { console.log('Shutting down chromecast...'); server.close(); device.close(function(err) { if (err) console.log('error closing chromecast ', err); process.exit(0); }); } process.on('SIGINT', terminate) process.on('SIGTERM', terminate)
-
I cleaned up my .npm/_logs folder. When I run the script there is no new log created…
The new script results in the same error. The announced port 1901 is not open. Have really no idea what could be the problem. I will give it a try tomorrow.
How fast reacts your GH to play the sound after you start the script? In the past I tried castnow, but the delay was really big. -
Port 1901 was announced in the command line output when I start the letgaspeak.js script. See some post above.
You will findError: connect ECONNREFUSED 0.0.0.0:1901
-
Sure
const ChromecastAPI = require('chromecast-api') var fs = require('fs'); var http = require('http'); server = http.createServer(function (req, res) { fs.readFile(__dirname + req.url, function (err,data) { if (err) { res.writeHead(404); res.end(JSON.stringify(err)); return; } res.writeHead(200); res.end(data); }); }).listen(8088); server.on('clientError', (err, socket) => { socket.end('HTTP/1.1 400 Bad Request\r\n\r\n'); }); var filename = process.argv[2]; var gaDevice = process.argv[3]; if (filename == null) { console.log('Filename missing'); process.exit(); } if (gaDevice == null) { console.log('GA name missing'); process.exit(); } const baseUrl = 'http://192.168.0.100:8088/'; const media = { url : baseUrl + filename } var device const client = new ChromecastAPI() client.on('device', function (_device) { device = _device console.log('Device',device.friendlyName,'found'); if (gaDevice == device.friendlyName) { device.play(media, function (err) { if (!err) console.log('Playing',media.url,'on your chromecast'); if (err) console.log('error: ', err); }) } }); client.on('error', function (err) { if (err) console.log('error: ', err); }); terminate = function() { console.log('Shutting down chromecast...'); server.close(); device.close(function(err) { if (err) console.log('error closing chromecast ', err); process.exit(0); }); } process.on('SIGINT', terminate) process.on('SIGTERM', terminate)
Only the baseUrl is differrent
-
Hi, a new day with new changes
I found an old Cromecast device and could test it successfully with 2 devices.
I removed the cast discovery function. You need to use the IP address of your cast device (Google Home,etc). I streams only to 1 device!
The new command string is ‘node letgaspeak.js <filename.mp3> <GA name> <GA IP address’.
Still need to put in your file servers ip address.var fs = require('fs'); var http = require('http'); server = http.createServer(function (req, res) { fs.readFile(__dirname + req.url, function (err,data) { if (err) { res.writeHead(404); res.end(JSON.stringify(err)); return; } res.writeHead(200); res.end(data); }); }).listen(8088); server.on('clientError', (err, socket) => { socket.end('HTTP/1.1 400 Bad Request\r\n\r\n'); }); var filename = process.argv[2]; var gaDevice = process.argv[3]; var gaIp = process.argv[4]; if (filename == null || gaDevice == null || gaIp == null) { console.log('Input missing'); process.exit(); } const baseUrl = 'http://192.168.xxx.xxx:8088/'; const media = { url : baseUrl + filename } const Device = require('chromecast-api/lib/device'); const opts = { name: 'Chromecast', friendlyName: gaDevice, host: gaIp } const device = new Device(opts) device.play(media.url, function(err) { if (!err) console.log('Playing ' + media.url + ' on ' + gaDevice); if (err) console.log('error: ', err); }); terminate = function() { console.log('Shutting down chromecast...'); server.close(); device.close(function(err) { if (err) console.log('error closing chromecast ', err); process.exit(0); }); } process.on('SIGINT', terminate) process.on('SIGTERM', terminate)
-
Hi,
yepp this works now. Really nice!!! THX
I test it on my notebook. The mp3 gets played really fast within 2s I will say. Will check later some bigger files!
Question: Is the friendlyName really necessary, when the IP is given as argument?Seems you are on the way to the next plugin… :D.
My python script supports to return current state (volume for now), set volume, play given text (tts), play mp3 (file). I will share it. But I have to clean it up…
Would be nice if you (or even other guys) could help to get it running not only on my notebook.
Or do you like to make all the stuff working with js. Maybe really an idea for a new plugin. As you saw, I don’t know much about js… But I now will start to learn…My current command strings for my python script are as following:
python googleRemoteControl.py <GA name>
>>return current VOL
(for now)
python googleRemoteControl.py <GA name> <vol>
>>sets VOL to given state
python googleRemoteControl.py <GA name> <text>
>>TTS with current VOL
python googleRemoteControl.py <GA name> <text> <vol>
>>TTS with given VOL
python googleRemoteControl.py <GA name> <mp3>
>>MP3 with current VOL
python googleRemoteControl.py <GA name> <mp3> <vol>
>>MP3 with given VOL
“GA name” is used to set the correct IP within the python script.
-
You are right, the friendly name is obsolete. It works also with only an IP (the script must be changed a bit ). You should test it also on a rpi with node 10 to be sure.
Your python functions can be converted into javascript and even a plugin.
As you know there’s already a pimatic-chromecast plugin. That plugin uses the mdns discovery function with some requirement for the different operating systems. That is the function I skipped to make the script simpler and just for playing 1 audio file. The pimatic-chromecast is currently not capable of steaming audio (info from readme) but its planned.So the question is what could be the function of the new plugin.
My idea is that it should be dedicated and something like- ‘playing a sound’ triggered by a rule
- tts a sentence from a rule
I will give it a try
-
You are right. There is a route map for the chromecast plugin, but currently it is quiet around it. You did this within a half day. Why not have plugins with overlappings. I could imagine, that some people are interested in such plugin.
I like more to start a script in this case to trigger multiple things. For others it is maybe enough to do one special action so the plugin is a great thing. As an 3rd functio it would be nice to get/set volume. The api chromecast api provides this feature. I will play a little bit around in the next days. I need to get a feeling for js. I am really new in this.
-
Very good, I made a first version of a plugin that’s capable of speaking text via rules
The volume could be set as an optional value in the rule.
I can make it with the volume and probably the mp3 file cast also and publish it.
You could be a co-contributer and extend or change the plugin? -
Sure I will give it a try. Ideas a there, but the skill needs to be improved…
On with npm version you are?
-
One answer from my side was still missing. The script works on my pimatic system as well. The mp3 must be in the same directory as the script and the script must be manually aborted. After the mp3 was play it command line is is busy. I must press
crtl+c
. -
No its fine. Need some simple playground for the start…
-
hi, you can test a first version of pimatic-sounds (v0.0.8).
The plugin lets you speak a text or play a mp3 file to a chromecast device.
The minimum node requirement is v8.You control it via a rule. The action syntax is:
play [text | file | stop] [“test text for tts” | “filename”] vol [0-100] on [SoundsDevice]
The 3 typical use cases are:
- play text “this is a nice text” vol 50 on mychromecast
- play file “nice-music.mp3” vol 25 on mychromecast
- play stop mychromecast
The mp3 filename may not contain spaces and the mp3’s must be placed in a folder ‘sounds’ in the home directory of Pimatic (mostly /home/pi/pimatic-app
Read the README for details