SetSource() public method

public SetSource ( [ stream, [ mimeType ) : void
stream [
mimeType [
return void
        private async void StartMediaElement()
        {
            // To use AudioCategory.BackgroundCapableMedia:
            // * OnWindows 8 set MediaControl.PlayPressed, MediaControl.PausePressed,
            //   MediaControl.PlayPauseTogglePressed and MediaControl.StopPressed.
            // * On Windows 8.1 set SystemMediaTransportControls.ButtonPressed.
            systemControls = SystemMediaTransportControls.GetForCurrentView();
            systemControls.ButtonPressed += OnButtonPressed;
            systemControls.IsPlayEnabled = true;
            systemControls.IsPauseEnabled = true;
            systemControls.PlaybackStatus = MediaPlaybackStatus.Playing;

            mediaPlayer = new MediaElement();
            mediaPlayer.AudioCategory = AudioCategory.BackgroundCapableMedia;
            mediaPlayer.AutoPlay = true;
            mediaPlayer.CurrentStateChanged += OnCurrentStateChanged;
            this.Content = mediaPlayer;

            HttpClient client = new HttpClient();

            // Add custom headers or credentials.
            client.DefaultRequestHeaders.Add("Foo", "Bar");

            //Uri uri = new Uri("http://localhost/song.mp3?slow=1000&?bufferlength=100000&lastModified=true");
            Uri uri = new Uri("http://video.ch9.ms/ch9/70cc/83e17e76-8be8-441b-b469-87cf0e6a70cc/ASPNETwithScottHunter_high.mp4");

            HttpRandomAccessStream stream = await HttpRandomAccessStream.CreateAsync(client, uri);

            // If you need to use HttpClient, use MediaElement.SetSource() instead of MediaElement.Source.
            mediaPlayer.SetSource(stream, stream.ContentType);
        }
        static public async Task StartTextToSpeech(string text)
        {
            if (!string.IsNullOrEmpty(text))
            {
                try
                {
                    if (_speech != null)
                    {
                        StopTextToSpeech();
                    }

                    var voice = GetSpeechVoice();
                    if (voice != null)
                    {
                        _speech = new SpeechSynthesizer();
                        _speech.Voice = voice;

                        SpeechSynthesisStream speechStream = await _speech.SynthesizeTextToStreamAsync(Utility.DecodeHtml(text));
                        _soundPlayer = new MediaElement();
                        _soundPlayer.SetSource(speechStream, speechStream.ContentType);
                        _soundPlayer.Play();
                    }
                }
                catch (Exception ex)
                {
                    AppLogs.WriteError("SpeechServices", ex);
                }
            }
        }
 public async Task GetMediaElement()
 {
     var element = new MediaElement();
     var elm = GetRandomElement();
     var stream = await elm.OpenAsync(FileAccessMode.Read);
     element.SetSource(stream, elm.ContentType);
     await PlayElement(element);
 }
        public async void Speak(string text)
        {
            var mediaElement = new MediaElement();
            var synth = new SpeechSynthesizer();
            var stream = await synth.SynthesizeTextToStreamAsync(text);

            mediaElement.SetSource(stream, stream.ContentType);
            mediaElement.Play();
        }
        public async void Speak(string text)
        {
            var mediaElement = new Windows.UI.Xaml.Controls.MediaElement();
            var synth        = new Windows.Media.SpeechSynthesis.SpeechSynthesizer();
            var stream       = await synth.SynthesizeTextToStreamAsync(text);

            mediaElement.SetSource(stream, stream.ContentType);
            mediaElement.Play();
        }
Beispiel #6
0
 private async void SongsList_Tapped(object sender, TappedRoutedEventArgs e)
 {
     MediaElement PlayMusic = new MediaElement();
     var _list = SongsList as ListView;
     var _song = (StorageFile)_list.SelectedItem;
     var stream = await _song.OpenAsync(FileAccessMode.Read);
     PlayMusic.SetSource(stream, _song.ContentType);
     PlayMusic.Play();
 }
        private async void SpeakText(MediaElement audioPlayer, string textToSpeak)
        {

            using (SpeechSynthesizer synthesizer = new SpeechSynthesizer())
            {
                SpeechSynthesisStream ttsStream = await synthesizer.SynthesizeTextToStreamAsync(textToSpeak);
                audioPlayer.SetSource(ttsStream, ""); // This starts the player because AutoPlay="True"

            }
        }
 public async void Speak(MediaElement audioPlayer, SpeechMessage speech)
 {
     var synth = new SpeechSynthesizer();
     var ttsStream = await synth.SynthesizeTextToStreamAsync(speech.Message);
     audioPlayer.SetSource(ttsStream, "");
     audioPlayer.CurrentStateChanged += async (object sender, Windows.UI.Xaml.RoutedEventArgs e) =>
     {
         await MainPage.Instance.SendResult(new ResultMessage(speech) { ResultId = (int)audioPlayer.CurrentState, Result = Enum.GetName(typeof(MediaElementState), audioPlayer.CurrentState) });
     };
 }
Beispiel #9
0
 private async void Fortune_Text_Click(object sender, TappedRoutedEventArgs e)
 {
     MediaElement media = new MediaElement();
     string text = textBlockFortune.Text;
     SpeechSynthesizer synthesizer = new SpeechSynthesizer();
     SpeechSynthesisStream stream = await synthesizer.SynthesizeTextToStreamAsync(text + ", God bless America");
     media.SetSource(stream, stream.ContentType);
     media.IsLooping = true;
     media.Play();
 }
		public async void Speak(string text)
		{
			SpeechSynthesizer synthesizer = new SpeechSynthesizer();
			SpeechSynthesisStream stream = await synthesizer.SynthesizeTextToStreamAsync(text);
			MediaElement media = new MediaElement();
			media.AutoPlay = true;
			media.SetSource(stream, stream.ContentType);
			media.Play();


		}
Beispiel #11
0
        public async Task PlayAsync(Stream speechStream, string contentFormat)
        {
            if (speechStream == null) throw new ArgumentNullException(nameof(speechStream));
            if (contentFormat == null) throw new ArgumentNullException(nameof(speechStream));

            var media = new MediaElement();
            media.SetSource(speechStream.AsRandomAccessStream(), contentFormat);
            media.Play();

            await Task.CompletedTask;
        }
Beispiel #12
0
        public async Task<bool> Play(string fileName)
        {
            var var_assets = await Package.Current.InstalledLocation.GetFolderAsync("Music");
            var var_file = await var_assets.GetFileAsync(fileName);
            var var_stream = await var_file.OpenAsync(FileAccessMode.Read);

            MediaElement m = new MediaElement();
            m.SetSource(var_stream, var_file.ContentType);
            m.Play();

            return true;
        }
        public async void Speak(string text)
        {
            MediaElement mediaElement = new MediaElement();

            var synth = new Windows.Media.SpeechSynthesis.SpeechSynthesizer();

            SpeechSynthesisStream stream = await synth.SynthesizeTextToStreamAsync("Hello World");

            mediaElement.SetSource(stream, stream.ContentType);
            mediaElement.Play();
            await synth.SynthesizeTextToStreamAsync(text);
        }
        public async Task SpeakAsync(string text)
        {
            var voice = SpeechSynthesizer.AllVoices
                .First(x => x.Gender.Equals(VoiceGender.Female) && x.Description.Contains("United States"));
            using (var speech = new SpeechSynthesizer { Voice = voice })
            {
                text = string.IsNullOrWhiteSpace(text) ? "There is no text to speak." : text;
                var stream = await speech.SynthesizeTextToStreamAsync(text);

                var media = new MediaElement { AutoPlay = true };
                media.SetSource(stream, stream.ContentType);
            }
        }
        public async Task Play(string fileName)
        {
            var packageLocation = Windows.ApplicationModel.Package.Current.InstalledLocation;
            var assetsFolder = await packageLocation.GetFolderAsync("Assets");

            var myAudio = await assetsFolder.GetFileAsync(fileName);
            if (myAudio != null)
            {
                var stream = await myAudio.OpenAsync(Windows.Storage.FileAccessMode.Read);
                MediaElement snd = new MediaElement();
                snd.SetSource(stream, myAudio.ContentType);
                snd.Play();
            }
        }  
Beispiel #16
0
        private async Task LoadMediaAsync()
        {
            try
            {
                StorageFile music_file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///data/Shopen.mp3"));

                var m_stream = await music_file.OpenReadAsync();

                music.SetSource(m_stream, "");
                music.Play();
                isPlaying = true;
            }
            catch (Exception ex) { Debug.WriteLine(ex.Message); isPlaying = false; }
        }
Beispiel #17
0
        public async Task Play( string fileName)
        {
            var packageLocation = Windows.ApplicationModel.Package.Current.InstalledLocation;
            var assetsFolder = await packageLocation.GetFolderAsync("assets");
            var soundsFolder = await assetsFolder.GetFolderAsync("sounds");
            StorageFile myAudio = await soundsFolder.GetFileAsync(fileName);

            _mediaElement = new MediaElement();
            
            var stream = await myAudio.OpenAsync(FileAccessMode.Read);
            _mediaElement.SetSource(stream, myAudio.ContentType);

            _mediaElement.Play();
        }
        async private void b1_Click(object sender, RoutedEventArgs e)
        {

            Windows.Storage.Pickers.FileOpenPicker picker = new Windows.Storage.Pickers.FileOpenPicker();
            picker.FileTypeFilter.Add(".avi");
            picker.FileTypeFilter.Add(".mp3");
            picker.FileTypeFilter.Add(".mp4");

            picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.ComputerFolder;
            var file = await picker.PickSingleFileAsync();
            MediaElement element = new MediaElement();
            b2 = element;
            if (file.FileType.Equals(".mp3"))
                element.SetSource(await file.OpenAsync(Windows.Storage.FileAccessMode.Read), "mp3");
        }
 private async void LoadSound(string SoundFilePath, MediaElement SoundElement)
 {
     // all sounds are stored in the Sounds folder
     try
     {
         Windows.Storage.StorageFolder folder = await Package.Current.InstalledLocation.GetFolderAsync("Sounds");
         Windows.Storage.StorageFile file = await folder.GetFileAsync(SoundFilePath);
         var stream = await file.OpenReadAsync();
         SoundElement.AutoPlay = false;
         SoundElement.SetSource(stream, file.ContentType);
     }
     catch
     {
         System.Diagnostics.Debug.WriteLine("Problem opening sound file: " + SoundFilePath);
     }
 }
		// http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj207057(v=vs.105).aspx
		public async void Speak(string text)
		{
			SpeechSynthesizer synth = new SpeechSynthesizer();

            try
            {
                var stream = await synth.SynthesizeTextToStreamAsync(text);

                var mediaElement = new MediaElement();
                mediaElement.SetSource(stream, stream.ContentType);
                mediaElement.Play();
            }
            catch (Exception pe) {
                Debug.WriteLine("couldn't play voice " + pe.Message);
            }
		}
       // SpeechRecognitionEngine sRecognize = new SpeechRecognitionEngine();


      
        private async void SpeakButton_Click(object sender, RoutedEventArgs e)
        {
            // The media object for controlling and playing audio.
            MediaElement mediaElement = new MediaElement();

            // The object for controlling the speech-synthesis engine (voice).
            SpeechSynthesizer synth = new Windows.Media.SpeechSynthesis.SpeechSynthesizer();



            // Generate the audio stream from plain text.
            SpeechSynthesisStream stream = await synth.SynthesizeTextToStreamAsync(txtText.Text);

            // Send the stream to the media object.
            mediaElement.SetSource(stream, stream.ContentType);
            mediaElement.Play();
        }
Beispiel #22
0
 /// <summary>
 /// Synthetize a text into a speech and pronounces it.
 /// </summary>
 /// <param name="message">The message to be pronounced.</param>
 public async Task TextToSpeech(string message)
 {
     try
     {
         if (!string.IsNullOrEmpty(message))
         {
             // Speak a string.
             var result = await Speech.SynthesizeTextToStreamAsync(message);
             _mediaElement = new MediaElement();
             _mediaElement.SetSource(result, result.ContentType);
             _mediaElement.Play();
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("SpeechServices", ex);
     }
 }
Beispiel #23
0
 public CN1Media(Stream s, string mime, java.lang.Runnable onComplete, Canvas cl)
 {
     this.cl = cl;
     using (AutoResetEvent are = new AutoResetEvent(false))
     {
         SilverlightImplementation.dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
         {
             elem = new MediaElement();
             cl.Children.Add(elem);
             elem.MediaOpened += elem_MediaOpened;
             elem.SetSource(s.AsRandomAccessStream(), "");
             video = mime.StartsWith("video");
             this.onComplete = onComplete;
             elem.MediaEnded += elem_MediaEnded;
             are.Set();
         }).AsTask().ConfigureAwait(false).GetAwaiter().GetResult();
         are.WaitOne();
     }
 }
        private async void talkItButtonTap(object sender, RoutedEventArgs e)
        {
            SpeechSynthesizer synth = new SpeechSynthesizer();
            string message = textBox.Text;

            if (message != null)
            {
                var stream = await synth.SynthesizeTextToStreamAsync(message);
                var media = new MediaElement();
                media.SetSource(stream, stream.ContentType);
                media.Play();
            }
            else
            {
                message = "Text box is empty";
                var stream = await synth.SynthesizeTextToStreamAsync(message);
                var media = new MediaElement();
                media.SetSource(stream, stream.ContentType);
                media.Play();
            }
        }
Beispiel #25
0
        public static async void SpeakText(string TTS)
        {
            try
            {
                var ttssynthesizer = new SpeechSynthesizer();

                //Set the Voice/Speaker
                using (var Speaker = new SpeechSynthesizer())
                {
                    Speaker.Voice = (SpeechSynthesizer.AllVoices.First(x => x.Gender == VoiceGender.Female));
                    ttssynthesizer.Voice = Speaker.Voice;
                }

                var ttsStream = await ttssynthesizer.SynthesizeTextToStreamAsync(TTS);

                //play the speech
                MediaElement media = new MediaElement();
                media.SetSource(ttsStream, " ");
            }
            catch (Exception ex) { }
        }
Beispiel #26
0
        private static async void _Speak(string text)
        {
            MediaElement mediaElement = new MediaElement();
            SpeechSynthesizer synth = new SpeechSynthesizer();


            foreach (VoiceInformation voice in SpeechSynthesizer.AllVoices)
            {
                Debug.WriteLine(voice.DisplayName + ", " + voice.Description);
            }

            // Initialize a new instance of the SpeechSynthesizer. 
            SpeechSynthesisStream stream = await synth.SynthesizeTextToStreamAsync(text);

            // Send the stream to the media object. 
            mediaElement.SetSource(stream, stream.ContentType);
            mediaElement.Play();

            mediaElement.Stop();
            synth.Dispose();
        }
Beispiel #27
0
        async Task DoLoadVideo()
        {
            var url = View.Path;

            if (url.IsEmpty())
            {
                return;
            }

            if (url.IsUrl())
            {
                if (View.AutoBuffer)
                {
                    await BufferVideo();
                }
            }
            else
            {
                try
                {
                    var file = Device.IO.File(url);
                    var data = await file.ReadAllBytesAsync();

                    var source = data.AsBuffer().AsStream().AsRandomAccessStream();
                    Result.SetSource(source, string.Empty);

                    View.VideoSize = await GetVideoSize(file : file);
                }
                catch (Exception ex)
                {
                    await Alert.Toast("Failed to show video: " + ex.Message);
                }
            }

            Result.AutoPlay  = View.AutoPlay;
            Result.IsLooping = View.Loop;

            Result.Loaded += (e, args) => View.LoadCompleted.Raise();
        }
Beispiel #28
0
        public async void PlayLaserSound()
        {
            var package = Windows.ApplicationModel.Package.Current;
            var installedLocation = package.InstalledLocation;
            
            var storageFile = await installedLocation.GetFileAsync("Assets\\Samples\\Kick 5.wav");
            if (storageFile != null)
            {
                var stream = await storageFile.OpenAsync(Windows.Storage.FileAccessMode.Read);
                MediaElement snd = new MediaElement();
                snd.SetSource(stream, storageFile.ContentType);
                snd.Play();
            }

            var storageFile2 = await installedLocation.GetFileAsync("Assets\\Samples\\Snare 5.wav");
            if (storageFile2 != null)
            {
                var stream = await storageFile2.OpenAsync(Windows.Storage.FileAccessMode.Read);
                MediaElement snd = new MediaElement();
                snd.SetSource(stream, storageFile2.ContentType);
                snd.Play();
            }
        }
        private async void TakeVideo()
        {
            ShowPicture = false;
            ShowVideo = true;

            var cameraCaptureUI = new CameraCaptureUI();
            cameraCaptureUI.VideoSettings.Format = CameraCaptureUIVideoFormat.Mp4;

            var video = await cameraCaptureUI.CaptureFileAsync(CameraCaptureUIMode.Video);

            if ( video != null)
            {
                _videoStream = await video.OpenAsync(FileAccessMode.Read);

                CapturedMedia = new MediaElement {AutoPlay = true};
                CapturedMedia.Loaded += (sender, args) =>
                                            {
                                                CapturedMedia.SetSource(_videoStream, "video/mp4");
                                                CapturedMedia.Play();
                                            };
            }

        }
Beispiel #30
0
 public async void HandleSpeakEvent(MediaElement mediaElement)
 {
     string currentLine = lineSection.line + lineSection.lineComplete;
     if (currentLine == "")
         return;
     SpeechSynthesisStream stream = await synth.SynthesizeTextToStreamAsync(currentLine);
     // if the SSML stream is not in the correct format throw an error message to the user
     if (stream == null)
     {
         MessageDialog dialog = new MessageDialog("unable to synthesize text");
         await dialog.ShowAsync();
         return;
     }
     // start this audio stream playing
     mediaElement.AutoPlay = true;
     mediaElement.SetSource(stream, stream.ContentType);
     mediaElement.Play();
     foreach (string word in currentLine.Split(' ')) loggedInUser.UpdateVocbulary(word);
     logSection.AddLineToLog(currentLine);
     lineSection.EnterLine();
 }
        private async void readAge(string age, string gender)
        {
            // The media object for controlling and playing audio.
            mediaElement = new MediaElement();

            // The object for controlling the speech synthesis engine (voice).
            var synth = new Windows.Media.SpeechSynthesis.SpeechSynthesizer();

            string adjetivo, faixaEtaria;
            if (gender == "male")
            {
                adjetivo = "sir";
            }
            else
            {
                adjetivo = "miss";
            }

            if (Int16.Parse(age) < 25)
            {
                faixaEtaria = "a young person";
            }
            else if (Int16.Parse(age) > 50)
            {
                faixaEtaria = "a growth " + gender;
            }
            else
            {
                faixaEtaria = "";
            }

            // Generate the audio stream from plain text.
            SpeechSynthesisStream stream;

            if (isSmiling && Int16.Parse(age) < 25)
            {
                stream = await synth.SynthesizeTextToStreamAsync("Hello " + adjetivo + "! Today you're looking " + faixaEtaria + " with " + age + " years old. Now I understand your smile.");
            }
            else if (!isSmiling && Int16.Parse(age) > 25)
            {
                stream = await synth.SynthesizeTextToStreamAsync("Hello " + adjetivo + "! Before I tell you your age, let me tell to you to try to smile to the photo next time. Maybe you can look younger. Today you're looking " + faixaEtaria + " with " + age + " years old.");
            }
            else if (!isSmiling)
            {
                stream = await synth.SynthesizeTextToStreamAsync("Hello " + adjetivo + "! Really? No smiles? OK. Today you're looking " + faixaEtaria + " with " + age + " years old.");
            }
            else
            {
                stream = await synth.SynthesizeTextToStreamAsync("Hello " + adjetivo + "! Today you're looking " + faixaEtaria + " with " + age + " years old. Before I forget: beautiful smile!");
            }

            // Send the stream to the media object.
            mediaElement.SetSource(stream, stream.ContentType);
            mediaElement.Play();
        }
        private async void ReadVoiceName(string name)
        {
            // The media object for controlling and playing audio.
            mediaElement = new MediaElement();

            // The object for controlling the speech synthesis engine (voice).
            var synth = new Windows.Media.SpeechSynthesis.SpeechSynthesizer();

            // Generate the audio stream from plain text.
            SpeechSynthesisStream stream;
           
            if (name == "Hara")
            {
                stream = await synth.SynthesizeTextToStreamAsync("Hello " + name + "! You have 18 years old plus " + (Int16.Parse(age) - 18).ToString() + " years of experience. But, let me check something for you.");
            }
            else
            {
                stream = await synth.SynthesizeTextToStreamAsync("Hello " + name + "! Let me check some products for you.");
            }

            // Send the stream to the media object.
            mediaElement.SetSource(stream, stream.ContentType);
            mediaElement.Play();
        }
        private async void ReadVoice(Error name)
        {
            // The media object for controlling and playing audio.
            mediaElement = new MediaElement();

            // The object for controlling the speech synthesis engine (voice).
            var synth = new Windows.Media.SpeechSynthesis.SpeechSynthesizer();

            // Generate the audio stream from plain text.
            SpeechSynthesisStream stream;
            switch (name)
            {
                case Error.Not_Recognized:
                    stream = await synth.SynthesizeTextToStreamAsync("Oops! Someone was do not recognized. Please, show me someone that I met before!");
                    break;
                case Error.No_Face:
                    stream = await synth.SynthesizeTextToStreamAsync("I can't find a face. Do you really show me someone? Please, try again.");
                    break;
                case Error.Not_Found:
                    stream = await synth.SynthesizeTextToStreamAsync("I can't find another product for you.");
                    break;
                case Error.Expensive:
                    stream = await synth.SynthesizeTextToStreamAsync("You need to order your boss to raise your paycheck. Let me check another product for you, for now.");
                    break;
                default:
                    stream = await synth.SynthesizeTextToStreamAsync("Hello " + name + "! Let me check some products for you.");
                    break;
            }
            // Send the stream to the media object.
            mediaElement.SetSource(stream, stream.ContentType);
            mediaElement.Play();
        }