Last active
March 23, 2018 17:06
-
-
Save jrwarwick/fc1b9ceddaec0bbb37a88ca4c4f6c635 to your computer and use it in GitHub Desktop.
Simple virtual display via HTTP for Mycroft
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Extremely low quality quick and dirty simulation of "dynamic data" feeding the mycroft httProjection. | |
| # It does underscore how simple and easy and yet still pretty flexible this is, though. | |
| pgrep -f 'python.*SimpleHTTPServer' || echo -e "the first thing you will want to do is start up the http service process with this command:\n\t python -m SimpleHTTPServer 8000 " | |
| COUNTER=2 | |
| DORMANCY=2 | |
| until [ $COUNTER -lt 1 ]; do | |
| echo COUNTER $COUNTER | |
| echo " : - ) " > face.txt | |
| sleep $DORMANCY | |
| echo " : - | " > face.txt | |
| sleep $DORMANCY | |
| echo " : - \ " > face.txt | |
| sleep $DORMANCY | |
| echo " : - 0 " > face.txt | |
| echo " 'Maybe utterances are replicated here, too.' " > utterance.txt | |
| sleep $DORMANCY | |
| echo " 'Maybe utterances are replicated here, too. It might be nice to have a scrolling buffer of last 10 lines or something here.' " > utterance.txt | |
| sleep $DORMANCY | |
| echo " : - | " > face.txt | |
| sleep $DORMANCY | |
| echo " : - 0 " > face.txt | |
| echo " 'let me show you a cool sword' " > utterance.txt | |
| sleep $DORMANCY | |
| echo " --=====]==0 " > artifact.txt | |
| sleep $DORMANCY | |
| echo " : - ) " > face.txt | |
| sleep $DORMANCY | |
| echo " If you had asked me to show you an unladen swallow, I might show this " > utterance.txt | |
| sleep $DORMANCY | |
| echo "<img src='https://upload.wikimedia.org/wikipedia/commons/thumb/5/5c/South_African_cliff_swallow%2C_Petrochelidon_spilodera%2C_at_Suikerbosrand_Nature_Reserve%2C_Gauteng%2C_South_Africa_%2822747098474%29.jpg/1200px-South_African_cliff_swallow%2C_Petrochelidon_spilodera%2C_at_Suikerbosrand_Nature_Reserve%2C_Gauteng%2C_South_Africa_%2822747098474%29.jpg' style='width:60%;height:auto;'/> " > artifact.txt | |
| sleep $DORMANCY | |
| sleep $DORMANCY | |
| sleep $DORMANCY | |
| echo "" > artifact.txt | |
| sleep $DORMANCY | |
| echo " 8 - ) " > face.txt | |
| let COUNTER-=1 | |
| done | |
| echo "<p>" > utterance.txt | |
| egrep -she '- (Utterance|Speak):' /var/log/mycroft-audio.log /var/log/mycroft-speech-client.log | sort -n | tail -20 | sed 's/^.* - Speak:/<\/p><p class="mycroft_speech">Mycroft: /' | sed "s/^.* - Utterance: \[u'\(.*\)'\]/<\/p><p class=\"human_speech\">\1/" >> utterance.txt | |
| echo "</p>" >> utterance.txt | |
| echo "" > artifact.txt | |
| sleep $DORMANCY | |
| sleep $DORMANCY | |
| sleep $DORMANCY | |
| echo "" > utterance.txt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE HTML> | |
| <html> | |
| <head> | |
| <meta http-equiv="refresh" content="4"> <!-- OR use the timers and ajax anyway --> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/zepto/1.2.0/zepto.min.js"></script> | |
| <script type="text/javascript"> | |
| function change_time() | |
| { | |
| /* | |
| var d = new Date(); | |
| var curr_hour = d.getHours(); | |
| var curr_min = d.getMinutes(); | |
| var curr_sec = d.getSeconds(); | |
| if(curr_hour > 12) curr_hour = curr_hour - 12; | |
| var tdisp = document.getElementById('time') | |
| tdisp.innerHTML = curr_hour+':'+curr_min+':'+curr_sec; | |
| tdisp.innerHTML = curr_hour+':'+curr_min+':'+curr_sec; | |
| */ | |
| var dt = new Date(); | |
| var disptime=dt.getHours()+':'+('0' + dt.getMinutes()).slice(-2)+':'+('0' + dt.getSeconds()).slice(-2); | |
| $("#time").html(disptime); | |
| } | |
| $(document).ready(function(){ | |
| change_time(); | |
| $.get('/utterance.txt', function(response){ | |
| $("#utterance").html(response); | |
| }); | |
| $.get('/face.txt', function(response){ | |
| $("#face").html(response); | |
| }); | |
| $.get('/artifact.txt', function(response){ | |
| $("#artifact").html(response); | |
| }); | |
| }); | |
| </script> | |
| <style> | |
| body { | |
| margin:2em; | |
| } | |
| #face { | |
| margin:1em; | |
| padding: .5em; | |
| font-size:2em; | |
| font-weight:bold; | |
| background-color: #C0DCF0; | |
| } | |
| #utterance { | |
| margin:1em; | |
| padding: .5em; | |
| font-size:1.25em; | |
| font-weight:bold; | |
| background-color: #EEEEDD; | |
| border: 1px solid grey; | |
| border-radius: 8px; | |
| } | |
| #utterance p.mycroft_speech { | |
| text-align: left; | |
| } | |
| #utterance p.human_speech { | |
| text-align: right; | |
| font-weight: normal; | |
| } | |
| #artifact { | |
| margin: 1em; | |
| font-family: consolas, mono; | |
| background-color: #FAFAFF; | |
| font-size: 1.1em; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <p> | |
| I am displaying via a simple http server via <code>python -m SimpleHTTPServer 8000</code> | |
| </p> | |
| <p> | |
| So you could point any local web user agent (that is running on an mdns capable os) at <a href="http://mycroft.local:8000/">http://mark1.local:8000/</a> to "see my face" or anything else I need to show you. | |
| </p> | |
| <p> | |
| In some other process, overwrite the content of some other file sitting in the "web root" such as face.json or displaystream.mp4 or something that a client-side fancy html5 thing will refresh or poll as well to make it dynamic. | |
| This could also include a copy of the data sent to enclosure display, so it "mirrors" that. But it could also supplement. If mycroft wants to "show you" something, it could be included in this page. | |
| This is a little bit like the IO streams concepts in *NIX OSs. | |
| </p> | |
| <p> | |
| Also when displaying URLs, this thing could do some client-side magic automatically include a QR code version. | |
| </p> | |
| <div id="utterance"> | |
| ... | |
| </div> | |
| <div id="face"> | |
| : - ) | |
| </div> | |
| <div id="artifact"> | |
| [x] | |
| </div> | |
| <table> | |
| <tr> | |
| <td>Current time is:</td> | |
| <td id="time"></td> | |
| <tr> | |
| </table> | |
| <!-- | |
| https://mycroft.ai/wp-content/uploads/2017/02/mark1.png | |
| --> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is raw, down and dirty. Clearly with some client-side magic and nice design this is transformed into something pretty nice. Imagine a special official little back-pack pico projector that plugs into Mycroft, pointing backwards. Put Mycroft close to a wall, and every time a wakeword is heard, this display begins projecting on the wall. After some sleep time, projection fades out. But you could just as well use a mobile phone or desktop computer or your modern gaming console to bring up the display as well.
Capability disabled/enabled by a voice command, of course. "Hey mycroft, disable visual display for a few hours."