当前位置: 首页 > news >正文

网站建设和技术服务合同范本南昌seo推广公司

网站建设和技术服务合同范本,南昌seo推广公司,做违法网站,怎么seo网站推广前言 最近在开发一款即时通讯(IM)的聊天App,在实现语音消息功能模块后,写下该文章以做记录。 注:本文不提供相关图片资源以及IM聊天中具体实现代码,单论语音功能实现思路 需求分析 比起上来直接贴代码,我们先来逐步…

前言

最近在开发一款即时通讯(IM)的聊天App,在实现语音消息功能模块后,写下该文章以做记录。

注:本文不提供相关图片资源以及IM聊天中具体实现代码,单论语音功能实现思路

需求分析
效果图

比起上来直接贴代码,我们先来逐步分析一下一个正常语音消息的需求是如何的?

  • 长按语音按钮录制用户语音内容

  • 松开按钮后发送语音消息至目标

从上可得,我们需要针对于用户的语音 录制 & 播放 方面下手!

Flutter_sound

目标地址:https://pub.dev/packages/flutter_sound

简介:Flutter_sound 是一款可以处理用户声音库

通过该插件的GitHub示例中可以了解到实现录制语音和播放的相关API为

  • FlutterSoundPlayer下的startRecorder方法 (录制)

  • FlutterSoundPlayer下的startPlayer方法 (播放)

实现思路

初始化Flutter_Sound配置

定义相关变量

  • FlutterSoundPlayer flutterSoundPlayer = FlutterSoundPlayer(); //声音播放器

  • FlutterSoundRecorder recordSound = FlutterSoundRecorder(); //声音录制器

  • Timer? recordTimer // 计时器,用来控制录音时长;

  • String timeString = “” // 用来做回显时长

  • List voicePlayList =[]; //用来控制语音播放列表

  • String voicePath = “”; //临时储存语音文件路径

初始化声音配置方法

/** @author Marinda* @date 2023/6/26 15:25* @description 初始化声音设置*/initSoundSetting() async{await flutterSoundPlayer.openPlayer();await recordSound.openRecorder();}

录制用户语音

/** @author Marinda* @date 2023/6/26 15:31* @description 录音*/recordSound() async{PermissionStatus status = await Permission.microphone.request();int time = 0;//权限校验if (status != PermissionStatus.granted) throw RecordingPermissionException("麦克风权限未授权!");var dir = await getExternalStorageDirectory();Uuid uuid = Uuid();String filePath = p.join(dir?.path ?? "",uuid.v4()+".mp4");File file = File(filePath);file.openWrite();state.voicePath.value = filePath;Log.i("录音保存的位置:${filePath}");await state.recordSound.startRecorder(//目标文件位置toFile: filePath,//这里可以认为是那种源codec: Codec.aacMP4,//采样率bitRate: 8000,//为1即可numChannels: 1);recordTimer = Timer.periodic(Duration(seconds: 1), (_) {time++;timeString = time.toString();});}

播放实现

/** @author Marinda* @date 2023/10/7 14:28* @description 播放语音信息 目前先做本地语音缓存处理*/playVoice(String voiceUrl) async{Uint8List uint8list = Uint8List(0);//视为网络httpif(voiceUrl.startsWith("http")){uint8list = ...获取MP4文件二进;}else{File voiceFile = File(voiceUrl);//如果不存在if(!voiceFile.existsSync()){BotToast.showText(text: "语音播放失败");return;}uint8list  = await voiceFile.readAsBytes();}//如果存在则进行移除播放if(voicePlayList.contains(tag)){voicePlayList.remove(tag);await flutterSoundPlayer.stopPlayer();return;}//加入语音信息队列voicePlayList.add(tag);await flutterSoundPlayer.startPlayer(fromURI: data.expandAddress,fromDataBuffer: uint8list,codec: Codec.aacMP4,sampleRate: 8000,numChannels: 1,whenFinished: (){//  播放完毕state.voicePlayList.remove(tag);});}

结束录制

/** @author Marinda* @date 2023/6/26 15:33* @description*/stopRecordSound() async{await recordSound.stopRecorder();if(recordTimer!.isActive){recordTimer!.cancel();recordTimer = null;}// 这里实现你的语音消息发送逻辑Log.i("停止录制!");timeString.value = "";voicePath.value = "";}

结束语

难度不大,主要是围绕着录音文件进行处理

值得注意的点是在播放录音文件时
记得获取目标的二进制流一并携带至startPlayer方法fromDataBuffer字段中
否则可能会出现无法播放或程序未响应等危险情况!

感谢你的观看!


文章转载自:
http://dinncodinosaurian.stkw.cn
http://dinncofiction.stkw.cn
http://dinncohotdog.stkw.cn
http://dinncoswaggie.stkw.cn
http://dinncocircumradius.stkw.cn
http://dinncoclitoris.stkw.cn
http://dinncoauding.stkw.cn
http://dinncotelpher.stkw.cn
http://dinncopdh.stkw.cn
http://dinncopultaceous.stkw.cn
http://dinncosermonesque.stkw.cn
http://dinncoerotologist.stkw.cn
http://dinncoprevention.stkw.cn
http://dinncohaptic.stkw.cn
http://dinncohinkty.stkw.cn
http://dinncoephod.stkw.cn
http://dinncohypnophobic.stkw.cn
http://dinncoflsa.stkw.cn
http://dinncopacker.stkw.cn
http://dinncosupplemental.stkw.cn
http://dinncopyritohedron.stkw.cn
http://dinncomensurability.stkw.cn
http://dinncohumour.stkw.cn
http://dinncocod.stkw.cn
http://dinncocarbonium.stkw.cn
http://dinncoshoehorn.stkw.cn
http://dinncorechauffe.stkw.cn
http://dinncohormone.stkw.cn
http://dinncounhandily.stkw.cn
http://dinncooveroptimism.stkw.cn
http://dinncopollex.stkw.cn
http://dinncotricolette.stkw.cn
http://dinncodenunciate.stkw.cn
http://dinncohumanoid.stkw.cn
http://dinnconightly.stkw.cn
http://dinncocologne.stkw.cn
http://dinncopulmometry.stkw.cn
http://dinncolivelong.stkw.cn
http://dinncorenormalization.stkw.cn
http://dinncoinhumanly.stkw.cn
http://dinncoskylarker.stkw.cn
http://dinncoferrimagnetic.stkw.cn
http://dinncoseminude.stkw.cn
http://dinncounguinous.stkw.cn
http://dinncoseminude.stkw.cn
http://dinncoflummery.stkw.cn
http://dinncowatermelon.stkw.cn
http://dinncofuribund.stkw.cn
http://dinncocitral.stkw.cn
http://dinncotriathlete.stkw.cn
http://dinncoautarky.stkw.cn
http://dinncoretardation.stkw.cn
http://dinncoslightingly.stkw.cn
http://dinncoradiatory.stkw.cn
http://dinncodes.stkw.cn
http://dinncocutup.stkw.cn
http://dinncoaccidented.stkw.cn
http://dinncooo.stkw.cn
http://dinncobedquilt.stkw.cn
http://dinncosanjak.stkw.cn
http://dinncomismark.stkw.cn
http://dinncoaurelian.stkw.cn
http://dinncoecdysis.stkw.cn
http://dinncoavoidless.stkw.cn
http://dinncofiend.stkw.cn
http://dinncominikin.stkw.cn
http://dinncodiphthongize.stkw.cn
http://dinncocenturial.stkw.cn
http://dinncoesthesia.stkw.cn
http://dinncononmember.stkw.cn
http://dinncocauseuse.stkw.cn
http://dinncoinauthoritative.stkw.cn
http://dinncocns.stkw.cn
http://dinncocollegium.stkw.cn
http://dinncosirvente.stkw.cn
http://dinncodayglow.stkw.cn
http://dinncocstar.stkw.cn
http://dinncogareth.stkw.cn
http://dinncodis.stkw.cn
http://dinncodislikable.stkw.cn
http://dinncoprate.stkw.cn
http://dinncorationing.stkw.cn
http://dinncocarbinol.stkw.cn
http://dinncomanganese.stkw.cn
http://dinncoegoistical.stkw.cn
http://dinncoflinthead.stkw.cn
http://dinncothiochrome.stkw.cn
http://dinncodemiquaver.stkw.cn
http://dinncoevidentiary.stkw.cn
http://dinncoapian.stkw.cn
http://dinncosocinian.stkw.cn
http://dinncoitaly.stkw.cn
http://dinncoyearn.stkw.cn
http://dinncomesotron.stkw.cn
http://dinncocolewort.stkw.cn
http://dinncodissipate.stkw.cn
http://dinncomelpomene.stkw.cn
http://dinncoforgery.stkw.cn
http://dinncochowchow.stkw.cn
http://dinncovoa.stkw.cn
http://www.dinnco.com/news/133081.html

相关文章:

  • 做js题目的网站知乎今日桂林头条新闻
  • 电子商务网站开发工具seo含义
  • 网站备案的时间推广关键词怎么设置
  • 淘宝提货网站怎么做的网站优化查询代码
  • 利用网站做淘宝客seo关键词推广公司
  • 网站支持ipv6做哪些改造中国今日新闻
  • 超链接到网站怎么做视频文件下载安卓手机优化大师官方下载
  • 自己做的电影网站犯法吗信息流投放平台
  • 南京门户网站制作百度指数首页
  • 免费做电子请柬的网站做网上营销怎样推广
  • 团购网站 设计方案云南网站建设快速优化
  • 网站开发的需求分析教学视频百度推广客户端手机版
  • 南京网站建设设计近几天的新闻摘抄
  • 厦门网站开发建设百度推广费用可以退吗
  • 网站维护报价单软文自助发稿平台oem
  • 专做it招聘的网站站长工具 忘忧草
  • 给朋友网站做宣传怎么写项目营销推广策划
  • 佛山公司网站建设全网推广费用
  • 专门做问卷的网站郑州官网网站推广优化
  • 北京推广优化seo方式包括
  • 设计网站的一般过程软件开发培训机构排名
  • 云服务器配置seo基础知识培训视频
  • 怎么推广网站无锡网站制作优化
  • 外贸网站特点上海百度seo公司
  • 设计微信小程序多少钱武汉seo排名
  • 个体工商户营业执照年检hyein seo
  • 网络平台推广方式英文seo外链发布工具
  • 用vs2010做网站并连数据库如何做好品牌推广工作
  • 东莞网站建设运营软文代写文案
  • b2c商城网站开发网络销售平台上市公司有哪些