예제 #1
0
        public MainPage()
        {
            this.InitializeComponent();

            speech = new SpeechSynthesizer(CLIENT_ID, CLIENT_SECRET);
            speech.AudioFormat = SpeakStreamFormat.MP3;
            speech.AudioQuality = SpeakStreamQuality.MaxQuality;
            speech.AutoDetectLanguage = false;
            speech.AutomaticTranslation = false;

            /* Database transactions */
            var db = new SQLiteConnection(Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "mydb.sqlite"));
            db.CreateTable<Button>();

            /* Get and insert sample buttons from system colors */
            var _Colors = typeof(Colors)
                .GetRuntimeProperties()
                .Select((x, i) => new
                {
                    Color = (Color)x.GetValue(null),
                    Name = x.Name,
                    Index = i,
                    ColSpan = 1,
                    RowSpan = 1
                });

            foreach (var c in _Colors)
            {
                db.Insert(new Button { Text = c.Name, ColSpan = c.ColSpan, RowSpan = c.RowSpan, Order = c.Index, ColorHex = c.Color.ToString() });
            }
            
            /* Set data context to Button table */
            this.DataContext = db.Table<Button>().ToList();
        }
예제 #2
0
 /// <summary>
 /// constructor
 /// </summary>
 public UcommSpeaker()
 {
     voice = new SpVoice();
     voice.Volume = 100;
     voice.Rate = 0;
     voiceFlag = SpeechVoiceSpeakFlags.SVSFlagsAsync | SpeechVoiceSpeakFlags.SVSFPurgeBeforeSpeak;
     speaker = new SpeechSynthesizer(Properties.Settings.Default.AZURE_CLIENT_ID, Properties.Settings.Default.AZURE_CLIENT_SECRET);
 }
        //
        // GET: /Home/
        public ActionResult index()
        {
            try
            {
                if (userSession.currentUser != null && userSession.currentUser.authenticate != 0)
                    return RedirectToAction("index", "User");
            }
            catch (Exception)
            {
            }
            SpeechSynthesizer speech = new SpeechSynthesizer("SmartAudioCityGuide", "Lz+vYpOFm6NTP83A9y0tPoX6ByJa06Q6yxHvoBsD0xo=");
            Thread thread = new Thread(new ThreadStart((Action)(() =>
                    {
                        try
                        {
                            speech.Speak("Smart Audio City Guide", "en");
                        }
                        catch (Exception)
                        {
                        }

                    }
             )));

            //connectController.getJson("http://localhost:12729/LocationsWebServices/searchLocations?location={currentLocation:null,id:0,latitude:-23.60623,longitude:-46.63943}&radius=1&windowsPhoneId=76:166:78:202:174:128:119:95:49:74:176:162:244:201:82:84:214:139:57:0:&code=wonders");

            /*
            RouteServicesController target = new RouteServicesController();
            string waypointString = string.Empty;
            string expected = string.Empty;
            string actual;
            actual = target.CreateRoute("38.9265353232622, -77.073235809803; 38.9230918884277, -77.0788726806641","0");

            string actual2 = target.MakeGeocodeRequest("avenida padre pereira de andrade 545, sao paulo sp");
            string actual3 = target.MakeReverseGeocodeRequest(actual2);

            target = new RouteServicesController();
            string actual5 = target.MakeGeocodeRequest("Avenida Paulista, 1969 Sao Paulo Brazil");
            if (!actual5.Contains("No location found.") && !actual5.Contains("An exception occurred."))
            {
                string actual4 = target.CreateRoute("-23.5372009, -46.7198792;" + actual5, "0");
                List<Route> routes = serializer.Deserialize<List<Route>>(actual4);
            }
            */

            thread.Start();
            ModelState.Merge((ModelStateDictionary)TempData["ModelState"]);

            return View();
        }
 public string sendLastCommentFromIdLocation(string idLocation, string code)
 {
     List<Comments> comments = new List<Comments>();
     Comments lastComment = new Comments();
     Stream resultStream;
     byte[] result;
     string resultJson;
     List<string> listChar = new List<string>();
     SpeechSynthesizer speech = new SpeechSynthesizer("SmartAudioCityGuide", "Lz+vYpOFm6NTP83A9y0tPoX6ByJa06Q6yxHvoBsD0xo=");
     comments = commentServices.findCommentByIdLocation(Convert.ToInt32(idLocation));
     lastComment = comments.Last();
     resultStream = speech.GetSpeakStream(lastComment.description,"pt");
     result = convertStreamToByteBuffer(resultStream);
     for (int i = 0; i < result.Length; i++)
     {
         listChar.Add(result[i].ToString());
     }
     resultJson = javaSerializer.Serialize(listChar);
     return resultJson;
 }
        public ActionResult addTextComment(Comments comment,string selectList)
        {
            SpeechSynthesizer speech = new SpeechSynthesizer("SmartAudioCityGuide", "Lz+vYpOFm6NTP83A9y0tPoX6ByJa06Q6yxHvoBsD0xo=");
            Stream stream;
            byte[] bytes;
            comment.isText = false;

            if (selectList == "--Select One--")
            {
                return RedirectToAction("index", "Maps");
            }

            else if(selectList == "Normal Mode")
            {
                comment.typeOfCommentsId = 1;
            }

            else if (selectList == "Exploration Mode")
            {
                comment.typeOfCommentsId = 2;
            }

            stream = speech.GetSpeakStream(comment.description);
            bytes = ReadFully(stream);
            comment.sound = convertBytesToString(bytes);

            try
            {
                locationServices.addLocations(location.currentLocation);
                comment.locationsId = location.currentLocation.id;
                comment.userId = user.currentUser.id;
            }
            catch
            {

            }

            commentsServices.addComment(comment);

            return RedirectToAction("index", "Maps");
        }
        private void holdWhere(object sender, System.Windows.Input.GestureEventArgs e)
        {
            //Moq
            //holdWhereMoq();
            //return;

            if (NetworkInterface.GetIsNetworkAvailable())
            {
                Thread thread = new Thread(new ThreadStart((Action)(() =>
                {
                    try
                    {
                        SpeechSynthesizer speech = new SpeechSynthesizer("SmartAudioCityGuide", "Lz+vYpOFm6NTP83A9y0tPoX6ByJa06Q6yxHvoBsD0xo=");
                        Routes routesServices = new Routes(Properties.getServerIP());
                        MyGPS gps = new MyGPS();
                        CultureInfo culture = new CultureInfo("en-US");
                        double currentLatitude = gps.actualLocation.Position.Location.Latitude;
                        double currentLongitude = gps.actualLocation.Position.Location.Longitude;
                        int esc = 60;
                        routesServices.getAddressFromCoordinates(currentLatitude.ToString(culture) + "," + currentLongitude.ToString(culture));
                        while (routesServices.routeDone == false && esc > 0)
                        {
                            Thread.Sleep(70);
                            esc--;
                        }
                        if (routesServices.country == null || routesServices.city == null || esc < 0)
                        {
                            sound.play("error");
                            return;
                        }
                        speech.SpeakAsync(routesServices.street, CultureInfo.CurrentCulture.ToString());
                    }
                    catch (Exception)
                    {
                    }
                }))); thread.Start();
            }
            else
            {
                sound.play("internet");
            }

        }
 public void youAreAt(object[] street)
 {
     if (street != null)
     {
         string resultSearch = street.FirstOrDefault().ToString();
         string talk = "You are at " + resultSearch;
         SpeechSynthesizer speech = new SpeechSynthesizer("SmartAudioCityGuide", "Lz+vYpOFm6NTP83A9y0tPoX6ByJa06Q6yxHvoBsD0xo=");
         try
         {
             speech.Speak(talk, "en");
         }
         catch (Exception)
         {
         }
     }
 }
        public string talkThis(string talk, string code)
        {
            Stream resultStream;
            byte[] result;
            string resultJson;
            List<string> listChar = new List<string>();
            SpeechSynthesizer speech = new SpeechSynthesizer("SmartAudioCityGuide", "Lz+vYpOFm6NTP83A9y0tPoX6ByJa06Q6yxHvoBsD0xo=");
            resultStream = speech.GetSpeakStream(talk);
            result = convertStreamToByteBuffer(resultStream);
            for (int i = 0; i < result.Length; i++)
            {
                listChar.Add(result[i].ToString());
            }
            resultJson = javaSerializer.Serialize(listChar);

            return resultJson;
        }
        public ActionResult editCommentWithId(int commentId , Comments comment, string selectList)
        {
            SpeechSynthesizer speech = new SpeechSynthesizer("SmartAudioCityGuide", "Lz+vYpOFm6NTP83A9y0tPoX6ByJa06Q6yxHvoBsD0xo=");
            Comments newComments = commentsServices.findCommentByIdComment(commentId);
            Stream stream;
            byte[] bytes;
            newComments.isText = false;

            if (selectList == "--Select One--")
            {
                return RedirectToAction("index", "Maps");
            }

            else if (selectList == "Normal Mode")
            {
                comment.typeOfCommentsId = 1;
            }

            else if (selectList == "Exploration Mode")
            {
                comment.typeOfCommentsId = 2;
            }

            stream = speech.GetSpeakStream(comment.description);
            bytes = ReadFully(stream);
            newComments.sound = convertBytesToString(bytes);
            newComments.typeOfCommentsId = comment.typeOfCommentsId;

            commentsServices.updateCommentForId(commentId, comment);

            return RedirectToAction("index", "Maps");
        }
        public ActionResult addTextCommentWithLocation(Comments comment ,int locationId)
        {
            SpeechSynthesizer speech = new SpeechSynthesizer("SmartAudioCityGuide", "Lz+vYpOFm6NTP83A9y0tPoX6ByJa06Q6yxHvoBsD0xo=");
            Stream stream;
            byte[] bytes;
            comment.isText = false;
            comment.locationsId = locationId;

            stream = speech.GetSpeakStream(comment.description);
            bytes = ReadFully(stream);
            comment.sound = convertBytesToString(bytes);

            try
            {
                comment.userId = user.currentUser.id;
            }
            catch
            {

            }

            commentsServices.addComment(comment);

            return RedirectToAction("index", "Maps");
        }
        public void addCommentToLocation(string streamOfComment, string latitude , string longitude)
        {
            SpeechAudioFormatInfo audioType = new SpeechAudioFormatInfo(1000,AudioBitsPerSample.Sixteen,AudioChannel.Mono);
            SpeechSynthesizer speech = new SpeechSynthesizer("SmartAudioCityGuide", "Lz+vYpOFm6NTP83A9y0tPoX6ByJa06Q6yxHvoBsD0xo=");
            byte[] streamString;
            Locations location = new Locations();
            byte[] buffer = new byte[10];
            MemoryStream stream = new MemoryStream();
            using (SpeechRecognitionEngine speechRecongnizeEngine = new SpeechRecognitionEngine())
            {
                location.latitude = Convert.ToDouble(latitude);
                location.longitude = Convert.ToDouble(longitude);
                locationsServices.addLocations(location);

                streamString = serializer.Deserialize<byte[]>(streamOfComment);
                buffer = new byte[streamString.Count()];

                stream.Write(buffer, 0, buffer.Length);

                // Add a handler for the LoadGrammarCompleted event.
                speechRecongnizeEngine.LoadGrammarCompleted +=
                  new EventHandler<LoadGrammarCompletedEventArgs>(speechRecongnizeEngine_LoadGrammarCompleted);

                // Add a handler for the SpeechRecognized event.
                speechRecongnizeEngine.SpeechRecognized +=
                new EventHandler<SpeechRecognizedEventArgs>(speechRecongnizeEngine_SpeechRecognized);

                speechRecongnizeEngine.LoadGrammar(new DictationGrammar());
                speechRecongnizeEngine.SetInputToAudioStream(stream, audioType);
                speechRecongnizeEngine.RecognizeAsync(RecognizeMode.Multiple);
            }
            using (SpeechRecognizer recognizer = new SpeechRecognizer())
            {

                // Create SemanticResultValue objects that contain cities and airport codes.
                SemanticResultValue chicago = new SemanticResultValue("Chicago", "ORD");
                SemanticResultValue boston = new SemanticResultValue("Boston", "BOS");
                SemanticResultValue miami = new SemanticResultValue("Miami", "MIA");
                SemanticResultValue dallas = new SemanticResultValue("Dallas", "DFW");

                // Create a Choices object and add the SemanticResultValue objects, using
                // implicit conversion from SemanticResultValue to GrammarBuilder
                Choices cities = new Choices();
                cities.Add(new Choices(new GrammarBuilder[] { chicago, boston, miami, dallas }));

                // Build the phrase and add SemanticResultKeys.
                GrammarBuilder chooseCities = new GrammarBuilder();
                chooseCities.Append("I want to fly from");
                chooseCities.Append(new SemanticResultKey("origin", cities));
                chooseCities.Append("to");
                chooseCities.Append(new SemanticResultKey("destination", cities));

                // Build a Grammar object from the GrammarBuilder.
                Grammar bookFlight = new Grammar(chooseCities);
                bookFlight.Name = "Book Flight";

                // Add a handler for the LoadGrammarCompleted event.
                recognizer.LoadGrammarCompleted +=
                  new EventHandler<LoadGrammarCompletedEventArgs>(recognizer_LoadGrammarCompleted);

                // Add a handler for the SpeechRecognized event.
                recognizer.SpeechRecognized +=
                  new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);
                // Attach event handlers for recognition events.
                recognizer.SpeechRecognized +=
                  new EventHandler<SpeechRecognizedEventArgs>(
                    SpeechRecognizedHandler);
                recognizer.EmulateRecognizeCompleted +=
                  new EventHandler<EmulateRecognizeCompletedEventArgs>(
                    EmulateRecognizeCompletedHandler);
                // Load the grammar object to the recognizer.
                recognizer.LoadGrammarAsync(bookFlight);
            }
        }
        /*private string TranslateMethod(string text,string from,string to)
        {
            string uri = "http://api.microsofttranslator.com/v2/Http.svc/Translate?text=" + System.Web.HttpUtility.UrlEncode(text) + "&from=" + from + "&to=" + to;

            HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(uri);
            httpWebRequest.Headers.Add("SmartAudioCityGuide", "Lz+vYpOFm6NTP83A9y0tPoX6ByJa06Q6yxHvoBsD0xo=");
            WebResponse response = null;
            try
            {
                response = httpWebRequest.GetResponse();
                using (Stream stream = response.GetResponseStream())
                {
                    System.Runtime.Serialization.DataContractSerializer dcs = new System.Runtime.Serialization.DataContractSerializer(Type.GetType("System.String"));
                    string translation = (string)dcs.ReadObject(stream);
                    return translation;
                }
            }
            catch(Exception e)
            {
            }
            return text;
        }*/
        private string TranslateMethod(string text,string from,string to)
        {
            string uri = "http://api.microsofttranslator.com/v2/Http.svc/Translate?text=" + System.Web.HttpUtility.UrlEncode(text) + "&from=" + from + "&to=" + to;
            SpeechSynthesizer speech = new SpeechSynthesizer("SmartAudioCityGuide", "Lz+vYpOFm6NTP83A9y0tPoX6ByJa06Q6yxHvoBsD0xo=");
            text = speech.Translate(text, to);
            Regex regex = new Regex("cabeça",
                RegexOptions.IgnoreCase | RegexOptions.Multiline);
            text = regex.Replace(text, "dirija-se");
            return text;
        }
        public ActionResult Index()
        {
            SpeechSynthesizer speech = new SpeechSynthesizer("SmartAudioCityGuide", "Lz+vYpOFm6NTP83A9y0tPoX6ByJa06Q6yxHvoBsD0xo=");
            List<Comments> commentsFromUser = new List<Comments>();
            string speak = "";
            try
            {
                commentsFromUser = commentServices.findCommentsByIdUser(userSession.currentUser.id);
            }
            catch
            {

            }

            ViewData["commentsFromUser"] = commentsFromUser;

            try
            {
                speak = "Welcome " + userSession.currentUser.name.ToString();
            }
            catch
            {

            }
            Thread thread = new Thread(new ThreadStart((Action)(() =>
            {
                try
                {
                    speech.Speak(speak, "en");
                }
                catch (Exception)
                {
                }

            }
             )));

            thread.Start();
            return View();
        }
예제 #14
0
        private void getRoute()
        {
            Routes routesServices = new Routes(Properties.getServerIP());
            SpeechSynthesizer speech = new SpeechSynthesizer("SmartAudioCityGuide", "Lz+vYpOFm6NTP83A9y0tPoX6ByJa06Q6yxHvoBsD0xo=");
            MyGPS gps = new MyGPS();
            CultureInfo culture = new CultureInfo("en-US");
            double dist,mindist;
            string orientation;
            double destLat = (Application.Current as App).latShared;
            double destLon = (Application.Current as App).lonShared;
            int cont = 0;
            thread = new Thread(new ThreadStart((Action)(() =>
            {
                try
                {

                    do
                    {
                        orientation = gps.actualLocation.Position.Location.Course.ToString(culture);
                        if (orientation == "NaN") orientation = "0";

                        currentLatitude = gps.actualLocation.Position.Location.Latitude;
                        currentLongitude = gps.actualLocation.Position.Location.Longitude;

                        routesServices.getAddressFromCoordinates(currentLatitude.ToString(culture) + "," + currentLongitude.ToString(culture));
                        while (routesServices.routeDone == false && cont < 100)
                        {
                            cont++;
                            Thread.Sleep(70);
                        }
                        if (routesServices.country == null || routesServices.city == null)
                        {
                            error();
                            return;
                        }
                        cont = 0;
                        routesServices.Route(currentLatitude.ToString(culture) + "," + currentLongitude.ToString(culture) + ";" + destLat.ToString(culture) + "," + destLon.ToString(culture) + " ; " + orientation + " ; " + CultureInfo.CurrentCulture.TwoLetterISOLanguageName);
                        while (routesServices.routeDone == false && cont<100)
                        {
                            cont++;
                            Thread.Sleep(70);
                        }
                        if (routesServices.route == null)
                        {
                            error();
                            return;
                        }
                        routes = routesServices.route;

                        dist = distance(routesServices.route[0].lat, routesServices.route[0].lon);
                        mindist = dist;

                        while (((mindist + epsilon) > dist) && routes.Count > 0 && endThread == false)
                        {

                            currentLatitude = gps.actualLocation.Position.Location.Latitude;
                            currentLongitude = gps.actualLocation.Position.Location.Longitude;

                            dist = distance(routesServices.route[0].lat, routesServices.route[0].lon);
                            if (mindist > dist) mindist = dist;

                            routesServices.getAddressFromCoordinates(currentLatitude.ToString(culture) + "," + currentLongitude.ToString(culture));

                            if (dist < epsilon)
                            {
                                routesServices.route.RemoveAt(0);
                                if (routesServices.route.Count > 0)
                                {
                                    dist = distance(routesServices.route[0].lat, routesServices.route[0].lon);
                                    mindist = dist;
                                }
                                if (routesServices.route.Count == 0)
                                {
                                    sound.play("success");
                                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                                    {
                                        NavigationService.GoBack();
                                    }
                                    );
                                    return;
                                }
                            }
                            /* Threads comuns nao podem alterar a UI, entao é necessario criar o evento como a thread de UI */
                            if (endThread == false)
                            {
                                Deployment.Current.Dispatcher.BeginInvoke(() =>
                                {
                                    OnChanged(EventArgs.Empty);
                                }
                                );
                                speech.SpeakAsync(routesServices.street + ". " + routesServices.route[0].description + ". In " + Convert.ToInt32(dist).ToString()  + " meters", CultureInfo.CurrentCulture.ToString());
                                Thread.Sleep(15000);
                            }
                        }
                    } while (routes.Count > 0 && endThread == false);
                    if (endThread == false)
                    {
                        Deployment.Current.Dispatcher.BeginInvoke(() =>
                            {
                                sound.play("success");
                                System.Threading.Thread.Sleep(750);
                                sound.play("selectlocation");
                                NavigationService.GoBack();
                            }
                            );
                        return;
                    }

                }
                /* Mandar mensagem de erro e voltar para pagina anterior */
                catch (Exception)
                {
                    if(endThread == false) error();
                    return;
                }
            })));
            thread.Start();
        }