• 语音播报


     //语音对讲
            public bool SpeackVoice(int IdentifyID,int UlChannelId, string filePath)
            {
                bool status = false;
                try
                {
                    LPPU_VOICE_INFO_S lppu = new LPPU_VOICE_INFO_S();
                    lppu.ulChannelId = UlChannelId;
                    lppu.szLocalAudioIp = "0.0.0.0";
                    lppu.bFeedAudioData = true;
                    lppu.szReserved = string.Empty;
                    int ulVoiceTBHandle = SDK.IVS_PU_StartVoiceBroadcast(IdentifyID, ref lppu);
                    int k = SDK.IVS_PU_GetLastError();
                    var erro = SDK.IVS_PU_GetErrorMsg(k);
                    Log.Info($"华为sdk-IVS_PU_StartVoiceBroadcast方法返回信息:{erro}");
                    int readLength = 0;  //定义读取的长度
                    long sentFileLength = 0;//定义发送的长度
                    int iOneLength = 340 * 3;
                    byte[] buffer = new byte[iOneLength];
                    using (FileStream fsRead = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Read))
                    {
                        long fileLength = fsRead.Length;//文件长度
                        while ((readLength = fsRead.Read(buffer, 0, buffer.Length)) > 0 && sentFileLength < fileLength)
                        {
                            sentFileLength += readLength;
                            IntPtr pName = IntPtr.Zero;
                            pName = Marshal.AllocHGlobal(buffer.Length);
                            Marshal.Copy(buffer, 0, pName, buffer.Length);
                            SDK.IVS_PU_FeedVoiceData(IdentifyID, ulVoiceTBHandle, pName, readLength, PU_ENCODE_TYPE_E.PU_ENC_G711U);
                            Marshal.FreeHGlobal(pName);//释放
                            Thread.Sleep(129);
                        }
                        Thread.Sleep(1000);
                        fsRead.Close();
                    }
                    bool stopstatus = SDK.IVS_PU_StopVoiceBroadcast(IdentifyID, ulVoiceTBHandle);//关闭语音播报
                    int r = SDK.IVS_PU_GetLastError();
                    var erro3 = SDK.IVS_PU_GetErrorMsg(r);
                    DelectDir(filePath);//播报完毕删除文件
                    if (stopstatus)
                    {
                        Log.Info($"关闭语音播报成功--{DateTime.Now}");
                    }
                    else
                    {
                        Log.Info($"关闭语音播报失败{erro3}--{DateTime.Now}");
                    }
                    bool Cancelstatus =  SDK.IVS_PU_Logout(IdentifyID);//注销设备
                    if (Cancelstatus)
                    {
                        Log.Info($"注销设备成功--{DateTime.Now}");
                    }
                    else
                    {
                        Log.Info($"注销设备失败--{DateTime.Now}");
                    }
                }
                catch (Exception ex)
                {
                    Log.Error($"语音播报错误{ex.Message}");              
                }
                finally
                {
                    var a = IPCLogout(IdentifyID);
                }
                return status;
            }
  • 相关阅读:
    利用Cubieborad破解WiFi
    从零开始——Mysql备份还原数据库
    从零开始——Ubuntu系统安装redis和phpredis
    监控应用卡顿BlockCanary
    2.AS内存分析
    热修复原理
    MultiDex 原理
    APP启动时白屏优化及multidex优化
    线程池的简便记忆方法
    2.volatile和AtomicXX
  • 原文地址:https://www.cnblogs.com/macT/p/11821246.html
Copyright © 2020-2023  润新知