Esempio n. 1
0
        public static async System.Threading.Tasks.Task <int> GetSampleRateAsync(string fileName)
        {
            Windows.Storage.StorageFile file = await Windows.Storage.StorageFile.GetFileFromPathAsync(Options.options.tempFolderPath + fileName);

            Windows.Storage.FileProperties.MusicProperties musicProperties = await file.Properties.GetMusicPropertiesAsync();

            Log.WriteLine("Synthesized Speech wave file: sample rate:" + musicProperties.Bitrate / Options.options.audio.bitDepth);
            return((int)musicProperties.Bitrate / Options.options.audio.bitDepth);
        }
Esempio n. 2
0
        public static async System.Threading.Tasks.Task <int> SynSpeechWriteToFileAsync(string text, string fileName)
        {
            using (Windows.Media.SpeechSynthesis.SpeechSynthesizer synth = new Windows.Media.SpeechSynthesis.SpeechSynthesizer())
            {
                try
                {
                    using (Windows.Media.SpeechSynthesis.SpeechSynthesisStream synthStream = await synth.SynthesizeTextToStreamAsyncServiceAsync(text, apiArgs)) // doesn't handle special characters such as quotes
                    {
                        // TODO: obsolete to use DataReader? use await Windows.Storage.FileIO.Read...(file);
                        using (Windows.Storage.Streams.DataReader reader = new Windows.Storage.Streams.DataReader(synthStream))
                        {
                            await reader.LoadAsync((uint)synthStream.Size);

                            Windows.Storage.Streams.IBuffer buffer     = reader.ReadBuffer((uint)synthStream.Size);
                            Windows.Storage.StorageFolder   tempFolder = await Windows.Storage.StorageFolder.GetFolderFromPathAsync(Options.options.tempFolderPath);

                            Windows.Storage.StorageFile srcFile = await tempFolder.CreateFileAsync(Options.options.audio.speechSynthesisFileName, Windows.Storage.CreationCollisionOption.ReplaceExisting);

                            await Windows.Storage.FileIO.WriteBufferAsync(srcFile, buffer);

                            Windows.Storage.FileProperties.MusicProperties musicProperties = await srcFile.Properties.GetMusicPropertiesAsync();

                            Log.WriteLine("Bitrate:" + musicProperties.Bitrate);

                            Windows.Media.MediaProperties.MediaEncodingProfile profile    = Windows.Media.MediaProperties.MediaEncodingProfile.CreateWav(Windows.Media.MediaProperties.AudioEncodingQuality.Low);
                            Windows.Media.Transcoding.MediaTranscoder          transcoder = new Windows.Media.Transcoding.MediaTranscoder();
                            Windows.Storage.StorageFile destFile = await tempFolder.CreateFileAsync(fileName, Windows.Storage.CreationCollisionOption.ReplaceExisting);

                            Windows.Media.Transcoding.PrepareTranscodeResult result = await transcoder.PrepareFileTranscodeAsync(srcFile, destFile, profile);

                            if (result.CanTranscode)
                            {
                                await result.TranscodeAsync();
                            }
                            else
                            {
                                Log.WriteLine("can't transcode file:" + result.FailureReason.ToString());
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
            return(0);
        }
Esempio n. 3
0
        /// <summary>
        /// Setting music class properties (active music should
        /// </summary>
        /// <returns></returns>
        public async Task <Music> ImportNewAsnyc()
        {
            try
            {
                Music _newMusic = new Music();
                //open file
                FileOpenPicker fileOpen = new FileOpenPicker();
                fileOpen.SuggestedStartLocation = PickerLocationId.Downloads;
                fileOpen.FileTypeFilter.Add(".MP3");
                fileOpen.FileTypeFilter.Add(".WAV");
                StorageFile filePicked = await fileOpen.PickSingleFileAsync();

                _newMusic.fileAccessToken = Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Add(filePicked);


                //extract music property
                Windows.Storage.FileProperties.MusicProperties musicProp = await filePicked.Properties.GetMusicPropertiesAsync();



                //var x = await musicProp.RetrievePropertiesAsync("Beats-per-minute");

                _newMusic.musicName     = musicProp.Title;
                _newMusic.musicArtist   = musicProp.Artist;
                _newMusic.musicDuration = ConvertDuration((double)musicProp.Duration.TotalSeconds);

                //add beat tag reading
                IDictionary <string, object> musicTags = await musicProp.RetrievePropertiesAsync(new string[] { "System.Music.BeatsPerMinute" });

                string bpmFromTags = musicTags["System.Music.BeatsPerMinute"].ToString();
                float  floatBpm    = 105;
                float.TryParse(bpmFromTags, out floatBpm);
                _newMusic.musicBPM = floatBpm;

                //TagLib.File tagFile = TagLib.File.Create(filePicked.Path);


                //replace with PCG to fill note sequence
                _newMusic.musicPunchKey = new List <PunchKey>();
                foreach (MusicMode mMode in Enum.GetValues(typeof(MusicMode)))
                {
                    if (mMode == MusicMode.Exercise || mMode == MusicMode.EasyChallenge || mMode == MusicMode.NormalChallenge || mMode == MusicMode.HardChallenge)
                    {
                        var      a           = (int)mMode;
                        PunchKey newPunchKey = new PunchKey();
                        //hanya generate untuk challenge, multiplayer nanti join dengan challenge
                        await newPunchKey.GenerateNoteSequence((int)mMode);

                        _newMusic.musicPunchKey.Add(newPunchKey);
                    }
                }

                //Change flag
                _newMusic.musicStatus = MusicFlags.Available;
                Debug.WriteLine("succes importing > " + _newMusic.musicName);
                return(_newMusic);
            }
            catch (Exception exc)
            {
                Debug.WriteLine("importing music fail > " + exc.Message.ToString());
                return(null);
            }
        }