Beispiel #1
0
        /// <summary>
        /// 开始录音
        /// </summary>
        public static void StartRecord(bool isGroup)
        {
            var filePath = isGroup
                ? publicMethod.localDataPath() + AntSdkService.AntSdkConfigInfo.AntSdkCompanyCode +
                           "\\" + AntSdkService.AntSdkLoginOutput.userId + "\\group\\RecordSound\\"
                : publicMethod.localDataPath() + AntSdkService.AntSdkConfigInfo.AntSdkCompanyCode +
                           "\\" + AntSdkService.AntSdkLoginOutput.userId + "\\personal\\RecordSound\\";

            _soundFilePath = filePath + Guid.NewGuid() + ".mp3";
            //检查文件夹是否存在
            if (!Directory.Exists(filePath))
            {
                Directory.CreateDirectory(filePath);
            }
            try
            {
                if (SoundCapture == null)
                {
                    SoundCapture = new Mp3SoundCapture();
                }
                foreach (var device in SoundCaptureDevice.AllAvailable)
                {
                    SoundCapture.CaptureDevice = device;
                }
                SoundCapture.OutputType = Mp3SoundCapture.Outputs.Mp3;
                SoundCapture.WaveFormat = PcmSoundFormat.Pcm44kHz16bitStereo;
                SoundCapture.Mp3BitRate = Mp3BitRate.BitRate32;
                SoundCapture.Start(_soundFilePath);
            }
            catch (Exception ex)
            {
                LogHelper.WriteError("[语音录制失败]:" + ex.Message + "," + ex.StackTrace);
            }
        }
 private void OnRecordingStopped(object sender, Mp3SoundCapture.StoppedEventArgs e)
 {
     if (e.Exception == null && _saveCallback != null)
     {
         _saveCallback(e.OutputFileName);
     }
 }
 public Mp3AudioRecorder()
 {
     _soundCapture = new Mp3SoundCapture();
     _soundCapture.NormalizeVolume = true;
     _soundCapture.CaptureDevice = SoundCaptureDevice.Default;
     _soundCapture.OutputType = Mp3SoundCapture.Outputs.Mp3;
     _soundCapture.WaveFormat = PcmSoundFormat.Pcm48kHz16bitStereo;
     _soundCapture.Mp3BitRate = Mp3BitRate.BitRate128;
     _soundCapture.Stopped += OnRecordingStopped;
     _soundCapture.WaitOnStop = true;
 }
Beispiel #4
0
 public SoundIO(SoundCaptureDevice captureDevice, Mp3SoundCapture.Outputs outputType, PcmSoundFormat soundFormat)
 {
     _mp3SoundCapture = new Mp3SoundCapture
     {
         CaptureDevice   = captureDevice,
         OutputType      = outputType,
         WaveFormat      = soundFormat,
         WaitOnStop      = true,
         NormalizeVolume = true
     };
 }
Beispiel #5
0
        /// <summary>
        /// 停止录音并返回音频文件
        /// </summary>
        public static string StopRecord()
        {
            SoundCapture.Stop();
            SoundCapture.Dispose();
            SoundCapture = null;
            if (!File.Exists(_soundFilePath))
            {
                return(null);
            }
            var file = new FileInfo(_soundFilePath);
            var size = file.Length;

            return(size == 0 ? null : _soundFilePath);
        }
Beispiel #6
0
        public DictophoneForm(CWorkersKeeper workersKeeper, string privateFolder)
        {
            InitializeComponent();

            _mp3SoundCapture = new Mp3SoundCapture
            {
                NormalizeVolume           = false,
                OutputType                = Mp3SoundCapture.Outputs.Wav,
                UseSynchronizationContext = true,
                WaitOnStop                = true
            };
            _mp3SoundCapture.Starting += mp3SoundCapture_Starting;
            _mp3SoundCapture.Stopped  += mp3SoundCapture_Stopped;

            _privateFolder = privateFolder;

            _configurationEngine = workersKeeper.ConfigurationEngine;
        }
Beispiel #7
0
 public VoiceRecorder()
 {
     mp3SoundCapture = new Mp3SoundCapture();
 }