Exemple #1
0
 /// <summary>
 /// 截取音频后,对每个小音频获语音转文字
 /// </summary>
 /// <param name="startMilliSecond">开始时间戳</param>
 /// <param name="endMilliSecond">结束时间戳</param>
 /// <param name="reader">音频流</param>
 /// <param name="i">用于创建新的文件</param>
 /// <param name="language">语言(zh,en)</param>
 /// <param name="splitTime">时间间隔</param>
 private void GetBaiduSpeech1(TimeSpan startMilliSecond, TimeSpan endMilliSecond, string sound_path, int i, string language, double splitTime)
 {
     try
     {
         var reader = new AudioFileReader(sound_path);
         //开始时间往前取startMilliSecond一半的偏移,结束时间往后取间隔时间的一半的偏移
         if (i == 0)
         {
             startMilliSecond = startMilliSecond - TimeSpan.FromMilliseconds(startMilliSecond.TotalMilliseconds / 2);
         }
         else
         {
             startMilliSecond = startMilliSecond - TimeSpan.FromMilliseconds(splitTime / 2);
         }
         if (endMilliSecond < reader.TotalTime)//最后一次不用取偏移
         {
             endMilliSecond = endMilliSecond + TimeSpan.FromMilliseconds(splitTime / 2);
         }
         TimeSpan span = endMilliSecond - startMilliSecond;
         if (span.TotalSeconds > 60)//超过60s,只取60秒
         {
             span = TimeSpan.FromSeconds(60);
         }
         var trimed = reader.Skip(startMilliSecond).Take(endMilliSecond - startMilliSecond);
         //保存新的音频文件
         string fileName  = Path.GetFileNameWithoutExtension(sound_path) + "_" + i + Path.GetExtension(sound_path);//重命名文件
         string newFolder = System.AppDomain.CurrentDomain.BaseDirectory + "NewSoundFiles/" + Path.GetFileNameWithoutExtension(sound_path) + "/";
         //重新存储到一个新的文件目录
         if (!System.IO.Directory.Exists(newFolder))
         {
             System.IO.Directory.CreateDirectory(newFolder);
         }
         string newFile = newFolder + fileName;
         WaveFileWriter.CreateWaveFile16(newFile, trimed);
         //绝对路径
         string path_absolute = context.Server.MapPath("/NewSoundFiles/" + Path.GetFileNameWithoutExtension(sound_path) + "/" + fileName);
         voiceFiles.Add(UploadFile.PostFile(path_absolute));
         if (span == TimeSpan.FromSeconds(60))//音频大于60s
         {
             //小音频
             var _reader = new AudioFileReader(sound_path);
             var _trimed = _reader.Skip(startMilliSecond).Take(span);
             //保存新的音频文件
             string _fileName = "_" + Path.GetFileNameWithoutExtension(sound_path) + "_" + i + Path.GetExtension(sound_path);//重命名文件
             string _newFile  = newFolder + _fileName;
             WaveFileWriter.CreateWaveFile16(_newFile, _trimed);
             baidu_text.Add(BaiduSpeech.BaiduTranslateToText(_newFile, language, _trimed.WaveFormat.SampleRate.ToString()));
         }
         else
         {
             baidu_text.Add(BaiduSpeech.BaiduTranslateToText(newFile, language, trimed.WaveFormat.SampleRate.ToString()));
         }
         reader.Close();
         reader.Dispose();
     }
     catch (Exception ex)
     {
         LogHelper.Error(ex.Message);
     }
 }
Exemple #2
0
        /// <summary>
        /// Main
        /// </summary>
        public Form1()
        {
            InitializeComponent();

            logger = new SimpleLogger();

            scanner = new TX400Scanner();
            OpenScanner();

            camera = new CameraCV();

            pcontroller = new PlatformController();
            OpenController();

            //调试用,直接对接百度API
            CVclient = new BaiduFace();

            speech = new BaiduSpeech();

            client = new APIClient();
            logger.Info("Get Client Token = " + APIClient.token);

            //启动timer,周期刷新picturebox
            pictureboxRefreshTimer           = new System.Timers.Timer();
            pictureboxRefreshTimer.Interval  = 1000;
            pictureboxRefreshTimer.Elapsed  += new System.Timers.ElapsedEventHandler(pictureboxRefresh);
            pictureboxRefreshTimer.AutoReset = true;
            pictureboxRefreshTimer.Start();

            //启动timer,周期刷新faceError
            faceErrorResetTimer           = new System.Timers.Timer();
            faceErrorResetTimer.Elapsed  += new System.Timers.ElapsedEventHandler(faceErrorReset);
            faceErrorResetTimer.AutoReset = true;
            faceErrorResetTimer.Interval  = 10000;
            faceErrorResetTimer.Start();

            //设置lock timer
            LockTimer          = new System.Timers.Timer();
            LockTimer.Elapsed += new ElapsedEventHandler(UnlockSystem);

            //open pictualbox always on
            SetPictureBoxVisibility(pictureBoxAlwaysOn, true);
        }