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

怎么样才能在网上卖东西抖音seo代理

怎么样才能在网上卖东西,抖音seo代理,seo实战培训费用,使用wordpress的购物网站文章目录 前言一、如何实现#xff1f;1.定义头结构2.预留头部空间3.写入PCM数据4.写入头部信息 二、完整代码三、使用示例总结 前言 之前实现了《C 将音频PCM数据封装成wav文件》#xff0c;最近将其改成了C#版本。使用C#实现录音功能时还是需要写wav文件的#xff0c;直接… 文章目录 前言一、如何实现1.定义头结构2.预留头部空间3.写入PCM数据4.写入头部信息 二、完整代码三、使用示例总结 前言 之前实现了《C 将音频PCM数据封装成wav文件》最近将其改成了C#版本。使用C#实现录音功能时还是需要写wav文件的直接用C#实现也是比较简单的这样可以免去不必要的依赖。 一、如何实现 首先需要构造wav头部wav文件音频信息全部保存在头部我们要做的就是在PCM数据的前面加入wav头并且记录PCM的相关参数。 1.定义头结构 只定义PCM格式的wav文件头包含3部分riff、format、data。需要使用[StructLayout(LayoutKind.Sequential)]描述结构体确保内存连续。 WAV头部 //WAV头部结构-PCM格式 [StructLayout(LayoutKind.Sequential)] struct WavPCMFileHeader {RIFF riffnew RIFF();Format format new Format();Data data new Data();public WavPCMFileHeader() { } }RTTF部分 [StructLayout(LayoutKind.Sequential)] struct RIFF {byte r (byte)R;byte i (byte)I;byte f (byte)F;byte t (byte)F;public uint fileLength 0;byte w (byte)W;byte a (byte)A;byte v (byte)V;byte e (byte)E;public RIFF() { } }Format部分 [StructLayout(LayoutKind.Sequential)] struct Format {byte f (byte)f;byte m (byte)m;byte t (byte)t;byte s (byte) ;public uint blockSize 16;public ushort formatTag0;public ushort channels 0;public uint samplesPerSec 0;public uint avgBytesPerSec 0;public ushort blockAlign 0;public ushort bitsPerSample 0;public Format() { } }Data部分 [StructLayout(LayoutKind.Sequential)] struct Data {byte d (byte)d;byte a (byte)a;byte t (byte)t;byte a2 (byte)a;public uint dataLength0;public Data() { } }2.预留头部空间 创建文件时预留头部空间 _stream File.Open(fileName, FileMode.Create); _stream!.Seek(Marshal.SizeOfWavPCMFileHeader(), SeekOrigin.Begin);3.写入PCM数据 写入数据 _stream!.Write(data);4.写入头部信息 关闭文件时回到起始位置写入头部信息 //写入头部信息 _stream!.Seek(0, SeekOrigin.Begin); WavPCMFileHeader h new WavPCMFileHeader(_channels, _sampleRate, _bitsPerSample, (uint)(_stream.Length - Marshal.SizeOfWavPCMFileHeader())); _stream!.Write(StructToBytes(h)); _stream!.Close(); _stream null;二、完整代码 .net6.0 WavWriter.cs using System.Runtime.InteropServices; /************************************************************************ * Project: AC::WavWriter * Decription: wav文件写入工具 * Verision: v1.0.0.0 * Author: Xin Nie * Create: 2023/10/8 09:27:00 * LastUpdate: 2023/10/8 18:28:00 ************************************************************************ * Copyright 2025. All rights reserved. ************************************************************************/ namespace AC { /// summary/// wav写入工具目前只支持pcm格式/// /summarypublic class WavWriter:IDisposable{ushort _channels;uint _sampleRate;ushort _bitsPerSample;FileStream? _stream;/// summary/// 创建对象/// /summary/// param namefileName文件名/param/// param namechannels声道数/param/// param namesampleRate采样率单位hz/param/// param namebitsPerSample位深/parampublic static WavWriter Create(string fileName, ushort channels, uint sampleRate, ushort bitsPerSample){return new WavWriter(fileName, channels, sampleRate, bitsPerSample); }/// summary/// 构造方法/// /summary/// param namefileName文件名/param/// param namechannels声道数/param/// param namesampleRate采样率单位hz/param/// param namebitsPerSample位深/paramWavWriter(string fileName, ushort channels, uint sampleRate, ushort bitsPerSample){_stream File.Open(fileName, FileMode.Create);_channels channels;_sampleRate sampleRate;_bitsPerSample bitsPerSample;_stream!.Seek(Marshal.SizeOfWavPCMFileHeader(), SeekOrigin.Begin);}/// summary/// 写入PCM数据/// /summary/// param namedataPCM数据/parampublic void Write(byte[] data){_stream!.Write(data);}/// summary/// 写入PCM数据/// /summary/// param namestreamPCM数据/parampublic void Write(Stream stream){stream.CopyTo(_stream!);}/// summary/// 关闭文件/// /summarypublic void Close(){//写入头部信息_stream!.Seek(0, SeekOrigin.Begin);WavPCMFileHeader h new WavPCMFileHeader(_channels, _sampleRate, _bitsPerSample, (uint)(_stream.Length - Marshal.SizeOfWavPCMFileHeader()));_stream!.Write(StructToBytes(h));_stream!.Close();_stream null;}public void Dispose(){Close();}static byte[] StructToBytesT(T obj){int size Marshal.SizeOf(typeof(T));IntPtr bufferPtr Marshal.AllocHGlobal(size);try{Marshal.StructureToPtr(obj!, bufferPtr, false);byte[] bytes new byte[size];Marshal.Copy(bufferPtr, bytes, 0, size);return bytes;}catch (Exception ex){throw new Exception(Error in StructToBytes ! ex.Message);}finally{Marshal.FreeHGlobal(bufferPtr);}} }//WAV头部结构-PCM格式[StructLayout(LayoutKind.Sequential)]struct WavPCMFileHeader{[StructLayout(LayoutKind.Sequential)]struct RIFF{byte r (byte)R;byte i (byte)I;byte f (byte)F;byte t (byte)F;public uint fileLength 0;byte w (byte)W;byte a (byte)A;byte v (byte)V;byte e (byte)E;public RIFF() { }}[StructLayout(LayoutKind.Sequential)]struct Format{byte f (byte)f;byte m (byte)m;byte t (byte)t;byte s (byte) ;public uint blockSize 16;public ushort formatTag0;public ushort channels 0;public uint samplesPerSec 0;public uint avgBytesPerSec 0;public ushort blockAlign 0;public ushort bitsPerSample 0;public Format() { }}[StructLayout(LayoutKind.Sequential)]struct Data{byte d (byte)d;byte a (byte)a;byte t (byte)t;byte a2 (byte)a;public uint dataLength0;public Data() { }}RIFF riffnew RIFF();Format format new Format();Data data new Data();public WavPCMFileHeader() { }public WavPCMFileHeader(ushort nCh, uint nSampleRate, ushort bitsPerSample, uint dataSize){riff.fileLength (uint)(36 dataSize);format.formatTag 1;format.channels nCh;format.samplesPerSec nSampleRate;format.avgBytesPerSec nSampleRate * nCh * bitsPerSample / 8;format.blockAlign (ushort)(nCh * bitsPerSample / 8);format.bitsPerSample bitsPerSample;data.dataLength dataSize;}}; }三、使用示例 using AC; try {using (var ww WavWriter.Create(test.wav, 2, 44100, 16)){byte[]data;//获取PCM数据//略//获取PCM数据-end//写入PCM数据ww.Write(data);} } catch (Exception e) {Console.WriteLine(e.Message); }总结 以上就是今天要讲的内容PCM封装成wav还是相对较简单的只要了解wav头结构,然后自定义其头结构然后再进行一定的测试就可以实现这样一个功能。
http://www.pierceye.com/news/976235/

相关文章:

  • 规划设计网站推荐自己做采集电影网站
  • 免费学编程的网站有哪些做网站设计用什么软件
  • 网站成品超市学室内设计去哪好
  • 网站备案一个主体无锡建设银行网站
  • delphi xe10网站开发台州做网站多少钱
  • 怎样设计卖奖的网站做电影网站哪个服务器好
  • 找外包公司做网站的好处和坏处wordpress 访问量大
  • 淄博 网站设计越秀公司网站建设
  • 网站该如何做本地网站搭建软件
  • 如何做汽车团购网站学做馒头面包哪个网站好
  • 中国科技成就总结莱芜网站优化排名公司
  • 中国建设银行网站企业网银收费北京网站建设小程序开发
  • 成交型网站倡导公司网络营销课程总结1000字
  • 网站建设注册前端开发培训机构推荐
  • 遵义网站推广中国房地产app下载安装最新版
  • c语言网站建设禅城网站开发
  • 宁波品牌网站制作哪家好太平阳电脑网网站模板
  • seo网站外链工具看设计比较好的网站
  • 济南道驰网站建设有限公司怎么样某网站网站的设计与实现
  • 服装印花图案设计网站设计一个网站要多久
  • ai怎么做自己的网站getpage wordpress使用详解
  • 龙岩做网站推广龙岗网站 建设深圳信科
  • 沈阳网站建设 网络服务广告公司首页
  • 旅游网站建设导航栏中国哪里正在大开发大建设
  • 哪能建设网站建设网站需要哪些流程图
  • 网站YYQQ建设o2o型网站
  • 给客户做网站 赚钱吗赣州省住房和城乡建设厅网站
  • 营销优化型网站怎么做手机app网页制作
  • 上海网站建设服wordpress友情链接排序
  • 沈阳市和平区网站建设编程课适合多大孩子学