0

已编辑

长按页面底部的橙色按钮以激活我正在谈论的内容,然后再次按下圆圈,并在出现提示时说“你好”,然后对出现的所有内容说“是”。

<html>

<head>

<title> Home </title>

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>

<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.0.js"></script>

<style type="text/css">

@font-face {
    font-family: "Roboto";
    src: url(System Fonts/Roboto-Light.ttf) format("truetype");
}

@font-face
{
font-family: "Roboto";
src: url('System Fonts/Roboto-Medium.ttf'),
font-weight:bold;
}

body {"Roboto", Arial, Sans-Serif;}

#perdify {
         position:fixed;
         bottom:0px;
         left:0px;
         background: #EFEFEF;
         width:100%;
         height:1.3cm;
}

#magic{   
  background-color: #dd4b39;
  -moz-border-radius: 50%;
  -webkit-border-radius: 50%;
  height:1.2cm; 
  width:1.2cm;
  left: 50%;
  margin-left: -0.6cm;
  position:absolute;
  bottom:0.05cm;

}


#main { 
                background:#ffffff; 
                width:100%;  
                display:none; 
                position:fixed;
                top:0.4cm;
                left:0px;
                bottom:1.3cm;
                overflow:auto;  
                z-index:2;  
}

.welcome { padding:10px; background-color: #EFEFEF; margin-top: 10px; margin-left:5px;  margin-right:5px; font-family: "Roboto", Arial, Sans-Serif;}

#statusbar {
         position:fixed;
         top:0px;
         left:0px;
         background: #EFEFEF;
         width:100%;
         height:0.4cm;
}

#voiceSearchGo::-webkit-input-speech-button {
  -webkit-appearance:none; 
  width:100%; 
  height:100%; 
  position:absolute;
  bottom:0px;
  left:0px; 
}

#voiceSearchGo:focus { outline: none; }

#voiceSearchGo {
  height:100%; 
  width:100%;
  color:transparent;
  background-color:transparent;
  position:absolute;
  bottom:0px;
  left:0px;
  border:none;  
  cursor:default;
}

#voicesearchstimulantcontainer {
  height:1.2cm;
  width:1.2cm;
  position:fixed;
  bottom:0.5mm;
  left: 50%;
  margin-left: -0.6cm; 
  display:none;
}

#micimage {position:absolute; top:0mm; left:0mm; height:1.2cm; width:1.2cm;}

.welcome { padding:10px; background-color: #EFEFEF; margin-top: 10px; margin-left:5px; margin-bottom: 10px; margin-right:5px; font-family: "Roboto", Arial, Sans-Serif;}
        .yousaid { padding:10px; background-color: #DD4B39; margin-bottom: 10px; margin-left:5px;  margin-right:5px; font-family: "Roboto", Arial, Sans-Serif; color:white;}  
        .yousaid h2 {margin: 0 0 5px 0; color:#EFEFEF;}
        .Onesearchsays { padding:10px; background-color: #EFEFEF; margin-top: 10px; margin-bottom: 10px; margin-left:5px;  margin-right:5px; font-family: "Roboto", Arial, Sans-Serif;} 
        .Onesearchsays h2 {margin: 0 0 5px 0; color:#DD4B39;}
        .buttonyes {padding:10px; background-color: #DD4B39;  margin-left:4%;  margin-right:4%; font-family: "Roboto", Arial, Sans-Serif; color:white; border:none; width:44%; font-weight:bold;} 
        .buttonno {padding:10px; background-color: #DD4B39; font-family: "Roboto", Arial, Sans-Serif; color:white; border:none; width:44%; font-weight:bold;}

#map { height:5cm; margin-left:-10px; margin-bottom:-10px; margin-right:-10px; margin-top:10px; }

</style>

</head>
<body>

<!--Start One Talk -->

<div id="main">
<div class="welcome" style=""> <h2 id="welcomemessage" style="margin: 0 0 10px 0; color:#DD4B39;"> How can I help You? </h2> Ps. Say 'help' for a list of Commands. </div>
</div>

<!--End One Talk -->

<!--Start status bar-->

<div id="statusbar"></div>

<!--End Status Bar-->

<!--Start Magic-->

<div id="perdify">  
<div id="magic"></div>

<div id="voicesearchstimulantcontainer">
<img src="System Icons/ic_action_microphone.png" alt="Click To Speak" id="micimage"/>
<input onfocus="this.value = '';" type="text" id="voiceSearchGo" x-webkit-speech></input>
</div>
</div>

<script>

var map;
  var infowindow;

voiceSearchGo.onwebkitspeechchange = function(e) {

var n = voiceSearchGo.value ;

var divYou = document.createElement("div"); 
divYou.id = "div1"; 
divYou.className = "yousaid"; 
divYou.innerHTML = "<h2> You Said . . . </h2>" + n ;
document.getElementById('main').appendChild(divYou); 

if ((n.split(" ",1)) == 'hello')
{

setTimeout(function() {

var time = new Date().getHours();

if (time == 3 )
{
var divGS = document.createElement("div"); 
divGS.id = "div1"; 
divGS.className = "Onesearchsays"; 
divGS.innerHTML = "<h2> One Search says . . . </h2>" +  "Good Morning, would You like to check the weather?" + "<BR></BR>" +  "<button type='button' class='buttonyes' onclick='morningdecisionyes()'> Yes </button>" + "<button type='button' class='buttonno' onclick='morningdecisionno()'> No </button>";
document.getElementById('main').appendChild(divGS); 
}

if (time == 4 )
{
var divGS = document.createElement("div"); 
divGS.id = "div1"; 
divGS.className = "Onesearchsays"; 
divGS.innerHTML = "<h2> One Search says . . . </h2>" +  "Good Morning, would You like to check the weather?" + "<BR></BR>" +  "<button type='button' class='buttonyes' onclick='morningdecisionyes()'> Yes </button>" + "<button type='button' class='buttonno' onclick='morningdecisionno()'> No </button>";
document.getElementById('main').appendChild(divGS); 
}

if (time == 5 )
{
var divGS = document.createElement("div"); 
divGS.id = "div1"; 
divGS.className = "Onesearchsays"; 
divGS.innerHTML = "<h2> One Search says . . . </h2>" +  "Good Morning, would You like to check the weather?" + "<BR></BR>" +  "<button type='button' class='buttonyes' onclick='morningdecisionyes()'> Yes </button>" + "<button type='button' class='buttonno' onclick='morningdecisionno()'> No </button>";
document.getElementById('main').appendChild(divGS); 
}

if (time == 6 )
{
var divGS = document.createElement("div"); 
divGS.id = "div1"; 
divGS.className = "Onesearchsays"; 
divGS.innerHTML = "<h2> One Search says . . . </h2>" +  "Good Morning, would You like to check the weather?" + "<BR></BR>" +  "<button type='button' class='buttonyes' onclick='morningdecisionyes()'> Yes </button>" + "<button type='button' class='buttonno' onclick='morningdecisionno()'> No </button>";
document.getElementById('main').appendChild(divGS); 
}

if (time == 7 )
{
var divGS = document.createElement("div"); 
divGS.id = "div1"; 
divGS.className = "Onesearchsays";  
divGS.innerHTML = "<h2> One Search says . . . </h2>" +  "Good Morning, would You like to check the weather?" + "<BR></BR>" +  "<button type='button' class='buttonyes' onclick='morningdecisionyes()'> Yes </button>" + "<button type='button' class='buttonno' onclick='morningdecisionno()'> No </button>";
document.getElementById('main').appendChild(divGS); 
}

if (time == 8 )
{
var divGS = document.createElement("div"); 
divGS.id = "div1"; 
divGS.className = "Onesearchsays"; 
divGS.innerHTML = "<h2> One Search says . . . </h2>" +  "Good Morning, would You like to check the weather?" + "<BR></BR>" +  "<button type='button' class='buttonyes' onclick='morningdecisionyes()'> Yes </button>" + "<button type='button' class='buttonno' onclick='morningdecisionno()'> No </button>";
document.getElementById('main').appendChild(divGS); 
}

if (time == 9 )
{
var divGS = document.createElement("div"); 
divGS.id = "div1"; 
divGS.className = "Onesearchsays"; 
divGS.innerHTML = "<h2> One Search says . . . </h2>" +  "Good Morning, would You like to check the weather?" + "<BR></BR>" +  "<button type='button' class='buttonyes' onclick='morningdecisionyes()'> Yes </button>" + "<button type='button' class='buttonno' onclick='morningdecisionno()'> No </button>";
document.getElementById('main').appendChild(divGS); 
}

if (time == 10 )
{
var divGS = document.createElement("div"); 
divGS.id = "div1"; 
divGS.className = "Onesearchsays"; 
divGS.innerHTML = "<h2> One Search says . . . </h2>" +  "Good Morning, would You like to check the weather?" + "<BR></BR>" +  "<button type='button' class='buttonyes' onclick='morningdecisionyes()'> Yes </button>" + "<button type='button' class='buttonno' onclick='morningdecisionno()'> No </button>";
document.getElementById('main').appendChild(divGS); 
}

if (time == 11 )
{
var divGS = document.createElement("div"); 
divGS.id = "div1"; 
divGS.className = "Onesearchsays"; 
divGS.innerHTML = "<h2> One Search says . . . </h2>" +  "Good Morning, would You like to check the weather?" + "<BR></BR>" +  "<button type='button' class='buttonyes' onclick='morningdecisionyes()'> Yes </button>" + "<button type='button' class='buttonno' onclick='morningdecisionno()'> No </button>";
document.getElementById('main').appendChild(divGS); 
}


if (time == 12)
{
var divGS = document.createElement("div"); 
divGS.id = "div1"; 
divGS.className = "Onesearchsays"; 
divGS.innerHTML = "<h2> One Search says . . . </h2>" + " Good Afternooon, would you like me to find you a near by cafe?" + "<BR></BR>" +  "<button type='button' class='buttonyes' onclick='noondecisionyes()'> Yes </button>" + "<button type='button' class='buttonno' onclick='noondecisionno()'> No </button>";
document.getElementById('main').appendChild(divGS); 
}

if (time == 13)
{
var divGS = document.createElement("div"); 
divGS.id = "div1"; 
divGS.className = "Onesearchsays"; 
divGS.innerHTML = "<h2> One Search says . . . </h2>" + " Good Afternooon, would you like me to find you a near by cafe?" + "<BR></BR>" +  "<button type='button' class='buttonyes' onclick='noondecisionyes()'> Yes </button>" + "<button type='button' class='buttonno' onclick='noondecisionno()'> No </button>";
document.getElementById('main').appendChild(divGS); 
}

if (time == 14)
{
var divGS = document.createElement("div"); 
divGS.id = "div1"; 
divGS.className = "Onesearchsays"; 
divGS.innerHTML = "<h2> One Search says . . . </h2>" + " Good Afternooon, would you like me to find you a near by cafe?" + "<BR></BR>" +  "<button type='button' class='buttonyes' onclick='noondecisionyes()'> Yes </button>" + "<button type='button' class='buttonno' onclick='noondecisionno()'> No </button>";
document.getElementById('main').appendChild(divGS); 
}

if (time == 15)
{
var divGS = document.createElement("div"); 
divGS.id = "div1"; 
divGS.className = "Onesearchsays"; 
divGS.innerHTML = "<h2> One Search says . . . </h2>" + " Good Afternooon, would you like me to find you a near by cafe?" + "<BR></BR>" +  "<button type='button' class='buttonyes' onclick='noondecisionyes()'> Yes </button>" + "<button type='button' class='buttonno' onclick='noondecisionno()'> No </button>";
document.getElementById('main').appendChild(divGS); 
}

if (time == 16)
{
var divGS = document.createElement("div"); 
divGS.id = "div1"; 
divGS.className = "Onesearchsays"; 
divGS.innerHTML = "<h2 id='evening'> One Search says . . .</h2>" + "Good Evening, would you like me to find you near by Restaurants and Bars?" + "<BR></BR>" + "<button type='button' class='buttonyes' onclick='Eveningdecisionyes()'> Yes </button>" + "<button type='button' class='buttonno' onclick='Eveningdecisionno()'> No </button>";
document.getElementById('main').appendChild(divGS); 
}

if (time == 17)
{
var divGS = document.createElement("div"); 
divGS.id = "div1"; 
divGS.className = "Onesearchsays"; 
divGS.innerHTML = "<h2 id='evening'> One Search says . . .</h2>" + "Good Evening, would you like me to find you near by Restaurants and Bars?" + "<BR></BR>" + "<button type='button' class='buttonyes' onclick='Eveningdecisionyes()'> Yes </button>" + "<button type='button' class='buttonno' onclick='Eveningdecisionno()'> No </button>";
document.getElementById('main').appendChild(divGS); 
}

if (time == 18)
{
var divGS = document.createElement("div"); 
divGS.id = "div1"; 
divGS.className = "Onesearchsays"; 
divGS.innerHTML = "<h2 id='evening'> One Search says . . .</h2>" + "Good Evening, would you like me to find you near by Restaurants and Bars?" + "<BR></BR>" + "<button type='button' class='buttonyes' onclick='Eveningdecisionyes()'> Yes </button>" + "<button type='button' class='buttonno' onclick='Eveningdecisionno()'> No </button>";
document.getElementById('main').appendChild(divGS); 
}

if (time == 19)
{
var divGS = document.createElement("div"); 
divGS.id = "div1"; 
divGS.className = "Onesearchsays"; 
divGS.innerHTML = "<h2 id='evening'> One Search says . . .</h2>" + "Good Evening, would you like me to find you near by Restaurants and Bars?" + "<BR></BR>" + "<button type='button' class='buttonyes' onclick='Eveningdecisionyes()'> Yes </button>" + "<button type='button' class='buttonno' onclick='Eveningdecisionno()'> No </button>";
document.getElementById('main').appendChild(divGS); 
}

if (time == 21)
{
var divGS = document.createElement("div"); 
divGS.id = "div1"; 
divGS.className = "Onesearchsays"; 
divGS.innerHTML = "<h2 id='evening'> One Search says . . .</h2>" + "Good Evening, would you like me to find you near by Restaurants and Bars?" + "<BR></BR>" + "<button type='button' class='buttonyes' onclick='Eveningdecisionyes()'> Yes </button>" + "<button type='button' class='buttonno' onclick='Eveningdecisionno()'> No </button>";
document.getElementById('main').appendChild(divGS); 
}

if (time == 22)
{
var divGS = document.createElement("div"); 
divGS.id = "div1"; 
divGS.className = "Onesearchsays"; 
divGS.innerHTML = "<h2 id='evening'> One Search says . . .</h2>" + "Good Evening, would you like me to find you near by Restaurants and Bars?" + "<BR></BR>" + "<button type='button' class='buttonyes' onclick='Eveningdecisionyes()'> Yes </button>" + "<button type='button' class='buttonno' onclick='Eveningdecisionno()'> No </button>";
document.getElementById('main').appendChild(divGS); 
}

if (time == 23)
{
var divGS = document.createElement("div"); 
divGS.id = "div1"; 
divGS.className = "Onesearchsays"; 
divGS.innerHTML = "<h2 id='evening'> One Search says . . .</h2>" + "Good Evening, would you like me to find you near by Restaurants and Bars?" + "<BR></BR>" + "<button type='button' class='buttonyes' onclick='Eveningdecisionyes()'> Yes </button>" + "<button type='button' class='buttonno' onclick='Eveningdecisionno()'> No </button>";
document.getElementById('main').appendChild(divGS); 
}

if (time == 24)
{
var divGS = document.createElement("div"); 
divGS.id = "div1"; 
divGS.className = "Onesearchsays"; 
divGS.innerHTML = "<h2 id='evening'> One Search says . . .</h2>" + "Good Evening, would you like me to find you near by Restaurants and Bars?" + "<BR></BR>" + "<button type='button' class='buttonyes' onclick='Eveningdecisionyes()'> Yes </button>" + "<button type='button' class='buttonno' onclick='Eveningdecisionno()'> No </button>";
document.getElementById('main').appendChild(divGS); 
}

if (time == 1)
{
var divGS = document.createElement("div"); 
divGS.id = "div1"; 
divGS.className = "Onesearchsays"; 
divGS.innerHTML = "<h2 id='evening'> One Search says . . .</h2>" + "Good Evening, would you like me to find you near by Restaurants and Bars?" + "<BR></BR>" + "<button type='button' class='buttonyes' onclick='Eveningdecisionyes()'> Yes </button>" + "<button type='button' class='buttonno' onclick='Eveningdecisionno()'> No </button>";
document.getElementById('main').appendChild(divGS); 
}

if (time == 2)
{
var divGS = document.createElement("div"); 
divGS.id = "div1"; 
divGS.className = "Onesearchsays"; 
divGS.innerHTML = "<h2 id='evening'> One Search says . . .</h2>" + "Good Evening, would you like me to find you close Restaurants and Bars?" + "<BR></BR>" + "<button type='button' class='buttonyes' onclick='Eveningdecisionyes()'> Yes </button>" + "<button type='button' class='buttonno' onclick='Eveningdecisionno()'> No </button>";
document.getElementById('main').appendChild(divGS); 
}

},1200);
} 

if ((n.split(" ",1)) == 'help' )
{
setTimeout(function() {

var divGS = document.createElement("div"); 
divGS.id = "div1"; 
divGS.className = "Onesearchsays"; 
divGS.innerHTML = "<h2 id='evening'> One Search Says . . . </h2>" + "Here is a list of commands . . ." + "<ol> <li>Search - Find an item in Google Search, ie: Search Panda.</li> <li>Show - Find an item in Google Images, ie: Show Panda.</li> <li>Wacth - Find an item on Youtube, ie: Watch Panda.</li> <li>Website - Go to a URL, ie: Website Panda.</li> <li>Weather - Display the current Temperature for your area.</li> <li>Find - Find a place on Google  Maps, ie: Find New York City.</li> <li>Hello - Recomendations based on time of day.</li> </ol>";
document.getElementById('main').appendChild(divGS);

},1200);
}


if ((n.split(" ",1)) == 'search' )
{
setTimeout(function() {

var divGS = document.createElement("div"); 
divGS.id = "div1"; 
divGS.className = "Onesearchsays"; 
divGS.innerHTML = "<h2 id='evening'> Search One for . . .</h2>" + "<i><p id='searchterm'>hello</p></i>" + "<button type='button' class='buttonyes' onclick='Eveningdecisionyes()'> Yes </button>" + "<button type='button' class='buttonno' onclick='Eveningdecisionno()'> No </button>";
document.getElementById('main').appendChild(divGS); 

},1200);
}

/* End Voice Commands */

}

function Eveningdecisionyes()
{

setTimeout(function() {

var divYou = document.createElement("div"); 
divYou.id = "div1"; 
divYou.className = "yousaid"; 
divYou.innerHTML = "<h2> You Chose . . . </h2>" + "Yes" ; 
document.getElementById('main').appendChild(divYou); 

},600);

setTimeout(function() {

var divGS = document.createElement("div"); 
divGS.id = "div1"; 
divGS.className = "Onesearchsays"; 
divGS.innerHTML = "<h2> One Search Says . . . </h2>" + "Here are some Restraunts and Bars within 10 kilometres of You . . ." + "<div id='map'>" + "</div>";
document.getElementById('main').appendChild(divGS);

setTimeout(function() { navigator.geolocation.getCurrentPosition(showPosition) },1);

    function showPosition(position)
    {

   var latlon = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);

    map = new google.maps.Map(document.getElementById('map'), {
      mapTypeId: google.maps.MapTypeId.ROADMAP,
      center: latlon,
      zoom: 15,
      disableDefaultUI: true
    });

    var request = {
      location: latlon,
      radius: 10000,
      types: ['bar', 'restaurant']
    };
    infowindow = new google.maps.InfoWindow();
    var service = new google.maps.places.PlacesService(map);
    service.search(request, callback);
  }

  function callback(results, status) {
    if (status == google.maps.places.PlacesServiceStatus.OK) {
      for (var i = 0; i < results.length; i++) {
        createMarker(results[i]);
     }
    }
   }

  function createMarker(place) {
    var placeLoc = place.geometry.location;
    var marker = new google.maps.Marker({
      map: map,
      position: place.geometry.location
    });
}
    google.maps.event.addListener(marker, 'click', function() {
      alert(place.name);
    });

},1200);

}

function Eveningdecisionno()
{

var divYou = document.createElement("div"); 
divYou.id = "div1"; 
divYou.className = "yousaid"; 
divYou.innerHTML = "<h2> You Chose . . . </h2>" + "no" ; 
document.getElementById('main').appendChild(divYou); 

}

function morningdecisionyes()
{
alert("yes");
}

function morningdecisionno()
{

var divYou = document.createElement("div"); 
divYou.id = "div1"; 
divYou.className = "yousaid"; 
divYou.innerHTML = "<h2> You Chose . . . </h2>" + "no" ; 
document.getElementById('main').appendChild(divYou); 

}

function noondecisionyes()
{
alert("yes");
}

function noondecisionno()
{

var divYou = document.createElement("div"); 
divYou.id = "div1"; 
divYou.className = "yousaid"; 
divYou.innerHTML = "<h2> You Chose . . . </h2>" + "no" ; 
document.getElementById('main').appendChild(divYou); 

}

</script>

<script type="text/javascript">

function playSound(soundfile) {
 document.getElementById("sounds").innerHTML=
 "<embed src=\""+soundfile+"\" hidden=\"true\" autostart=\"true\" loop=\"false\" />";
 };

$(window).load(function(){
var pressTimer

$("#magic").mouseup(function(){
  clearTimeout(pressTimer);

  return false;
}).mousedown(function(){
    pressTimer = window.setTimeout(function() { 

    $("#voicesearchstimulantcontainer").fadeIn('slow');

    if ($("#main").is(":hidden")) {
    $("#main").slideDown("slow");
    } else {
    $("#main").hide();
    };

    },500);

    },500);

  return false; 
});
}); 

</script>

</body>
</html>
4

2 回答 2

1

尝试var map;使用函数的外部。Google Maps API 要求 map 变量可以全局访问。

于 2012-10-10T11:34:15.757 回答
0

我已经解决了这个问题,愚蠢的我忘了包含地图 api js 库:( 抱歉所有的麻烦。

于 2012-10-11T02:39:32.817 回答