public void PlayAsync()
 {
     Finished      = false;
     _playingAsync = true;
     Task.Run(() =>
     {
         try
         {
             double lenMs    = SoundInfo.GetSoundLength(_fileName);
             DateTime stopAt = DateTime.Now.AddMilliseconds(lenMs);
             this.Play();
             while (DateTime.Now < stopAt)
             {
                 _ct.ThrowIfCancellationRequested();
             }
         }
         catch (OperationCanceledException)
         {
             base.Stop();
         }
         finally
         {
             OnSoundFinished();
         }
     }, _ct);
 }
        /// <summary>
        /// 完整音檔, 發到Google轉文字
        /// </summary>
        public static Task <SpeechData> FromFile(string path, string Language)
        {
            return(Task.Run(() =>
            {
                var sb = new StringBuilder();

                GCP.Share.Init();
                var response = GCP.Share.Client.Recognize(new RecognitionConfig()
                {
                    LanguageCode = Language,
                }, RecognitionAudio.FromFile(path));

                foreach (var result in response.Results)
                {
                    foreach (var alternative in result.Alternatives)
                    {
                        sb.Append(alternative.Transcript);
                    }
                }

                return new SpeechData
                {
                    WavFile = path,
                    Length = TimeSpan.FromMilliseconds(SoundInfo.GetSoundLength(path)),
                    Text = sb.ToString()
                };
            }));
        }
        /// <summary>
        /// Reloads displayed data from underlaying ResX node
        /// </summary>
        public override void UpdateDataOf(ListViewKeyItem item, bool reloadImages)
        {
            base.UpdateDataOf(item, reloadImages);

            LargeImageList.Images.Add(item.ImageKey, Editor.play);
            SmallImageList.Images.Add(item.ImageKey, Editor.play);

            FileInfo info = null;

            if (item.DataNode.FileRef != null && File.Exists(item.DataNode.FileRef.FileName))
            {
                info = new FileInfo(item.DataNode.FileRef.FileName);
            }

            if (info != null)
            {
                item.SubItems["Size"].Text   = GetFileSize(info.Length);
                item.SubItems["Length"].Text = GetSoundDigits(SoundInfo.GetSoundLength(info.FullName));
                item.FileRefOk = true;
            }
            else
            {
                var stream = item.DataNode.GetValue <MemoryStream>();
                if (stream != null)
                {
                    item.SubItems["Size"].Text   = GetFileSize(stream.Length);
                    item.SubItems["Length"].Text = null;
                    item.FileRefOk = true;
                }
                else
                {
                    item.FileRefOk = false;
                }
            }

            item.UpdateErrorSetDisplay();

            Validate(item);
            NotifyItemsStateChanged();

            if (item.ErrorMessages.Count > 0)
            {
                item.Status = KEY_STATUS.ERROR;
            }
            else
            {
                item.Status       = KEY_STATUS.OK;
                item.LastValidKey = item.Key;
            }

            string p = item.ImageKey;

            item.ImageKey = null;
            item.ImageKey = p;
        }
Example #4
0
 private void ReadSound(List <string> sounds)
 {
     if (sounds.Count > 0)
     {
         while (temp.Count > 0)
         {
             player.SoundLocation = (soundPath + temp[0]);
             int iTime = SoundInfo.GetSoundLength(player.SoundLocation.Trim()) - 0;
             player.Play();
             Thread.Sleep(iTime);
             temp.Remove(temp[0]);
         }
     }
     isFinishRead = true;
     playThread.Abort();
 }