声纹图-声谱图-js之wavesurfer.js(配置、事件、方法中文版翻译)

news2024/10/9 16:27:28

配置信息

optiontypedefaultEnglish descriptiontranslate
audioRatefloat1Speed at which to play audio. Lower number is slower.播放音频的速度。数值越低,速度越慢。
audioContextobjectnoneUse your own previously initialized AudioContext or leave blank.none
audioScriptProcessorobjectnoneUse your own previously initialized ScriptProcessorNode or leave blank.使用您自己先前初始化的ScriptProcessorNode或留空。
autoCenterbooleantrueIf a scrollbar is present, center the waveform around the progress.如果出现滚动条,则将波形围绕进度居中。
backendstringWebAudioWebAudio, MediaElement or MediaElementWebAudio. MediaElement is a fallback for unsupported browsers.WebAudio, MediaElement或MediaElementwebAudio。MediaElement是不受支持的浏览器的备用方案。
backgroundColorstringnoneChange background color of the waveform container.改变波形容器的背景颜色。
barGapnumbernoneThe optional spacing between bars of the wave, if not provided will be calculated in legacy format.波条之间的可选间距,如果没有提供,将以遗留格式计算。
barHeightnumber1Height of the waveform bars. Higher number than 1 will increase the waveform bar heights.波形条的高度。大于1的数字将增加波形条的高度。
barMinHeightnumbernullMinimum height to draw a waveform bar. Default behavior is to not draw a bar during silence.绘制波形条的最小高度。默认行为是在静默期间不画条。
barRadiusnumber0The radius that makes bars rounded.使bars变圆的半径
barWidthnumbernoneIf specified, the waveform will be drawn like this: ▁ ▂ ▇ ▃ ▅ ▂如果指定,波形将像这样绘制▁ ▂ ▇ ▃ ▅ ▂
closeAudioContextbooleanfalseClose and nullify all audio contexts when the destroy method is called.当destroy方法被调用时,关闭并使所有音频上下文无效。
containermixednoneCSS-selector or HTML-element where the waveform should be drawn. This is the only required parameter.css选择器或html元素,其中应该绘制波形。这是惟一必需的参数。
cursorColorstring#333The fill color of the cursor indicating the playhead position.指针的填充颜色,表示播放头位置。
cursorWidthinteger1Measured in pixels.以像素为单位
drawingContextAttributesobject{desynchronized: true}Specify canvas 2d drawing context attributes.指定画布2d绘图上下文属性。
fillParentbooleantrueWhether to fill the entire container or draw only according to minPxPerSec.是否填充整个容器或仅根据minPxPerSec绘制。
forceDecodebooleanfalseForce decoding of audio using web audio when zooming to get a more detailed waveform.在缩放时使用web音频强制解码音频以获得更详细的波形。
heightinteger128The height of the waveform. Measured in pixels.波形的高度。以像素为单位。
hideScrollbarbooleanfalseWhether to hide the horizontal scrollbar when one would normally be shown.是否在通常显示水平滚动条时隐藏水平滚动条。
hideCursorbooleanfalseHide the mouse cursor when hovering over the waveform. By default it will be shown.当鼠标光标悬停在波形上时隐藏鼠标光标。默认情况下会显示。
interactbooleantrueWhether the mouse interaction will be enabled at initialization. You can switch this parameter at any time later on.是否在初始化时启用鼠标交互。您可以在以后的任何时候切换该参数。
loopSelectionbooleantrue(Use with regions plugin) Enable looping of selected regions.(与区域插件一起使用)启用选定区域的循环。
maxCanvasWidthinteger4000Maximum width of a single canvas in pixels, excluding a small overlap (2 * pixelRatio, rounded up to the next even integer). If the waveform is longer than this value, additional canvases will be used to render the waveform, which is useful for very large waveforms that may be too wide for browsers to draw on a single canvas. This parameter is only applicable to the MultiCanvas renderer.单个画布的最大宽度(像素),不包括小重叠(2 * pixelRatio,四舍五入到下一个偶数)。如果波形长于此值,将使用额外的画布来渲染波形,这对于非常大的波形非常有用,因为浏览器可能太宽而无法在单个画布上绘制。此参数仅适用于multiccanvas渲染器。
mediaControlsbooleanfalse(Use with backend MediaElement) this enables the native controls for the media element.(与后端MediaElement一起使用)这将启用媒体元素的本机控件。
mediaTypestringaudio‘audio’ or ‘video’. Only used with backend MediaElement.“音频”或“视频”。仅用于后端MediaElement。
minPxPerSecinteger50Minimum number of pixels per second of audio.音频每秒的最小像素数。
normalizebooleanfalseIf true, normalize by the maximum peak instead of 1.0.如果为真,则通过最大峰值而不是1.0进行归一化。
partialRenderbooleanfalseUse the PeakCache to improve rendering speed of large waveforms.使用PeakCache来提高大波形的渲染速度。
pixelRatiointegerwindow.devicePixelRatioCan be set to 1 for faster rendering.可以设置为1以更快地呈现。
pluginsarray[]An array of plugin definitions to register during instantiation. They will be directly initialised unless they are added with the deferInit property set to true.在实例化期间注册的插件定义数组。它们将被直接初始化,除非添加时将deferInit属性设置为true。
progressColorstring#555The fill color of the part of the waveform behind the cursor. When progressColor and waveColor are the same the progress wave is not rendered at all.光标后面部分波形的填充颜色。当progressColor和waveColor相同时,进度波根本不会被渲染。
regionsMinLengthnumbernullDefault minLength for regions, in seconds. When creating a region, specifying the minLength parameter for that region will override this.默认minLength为区域,单位为秒。在创建区域时,为该区域指定minLength参数将覆盖该参数。
removeMediaElementOnDestroybooleantrueSet to false to keep the media element in the DOM when the player is destroyed. This is useful when reusing an existing media element via the loadMediaElement method.设置为false以在播放器被销毁时将media元素保留在DOM中。这在通过loadMediaElement方法重用现有媒体元素时非常有用。
rendererObjectMultiCanvasCan be used to inject a custom renderer.可用于注入自定义渲染器。
responsiveboolean or floatfalseIf set to true resize the waveform, when the window is resized. This is debounced with a 100ms timeout by default. If this parameter is a number it represents that timeout.如果设置为true,调整波形大小,当窗口调整大小时。默认情况下,这是一个100ms超时。如果此参数是一个数字,则表示超时时间。
scrollParentbooleanfalseWhether to scroll the container with a lengthy waveform. Otherwise the waveform is shrunk to the container width (see fillParent).是否滚动具有长波形的容器。否则波形将收缩到容器宽度(参见fillParent)。
skipLengthfloat2Number of seconds to skip with the skipForward() and skipBackward() methods.使用skipForward()和skipBackward()方法跳过的秒数。
splitChannelsbooleanfalseRender with seperate waveforms for the channels of the audio.渲染与单独的波形为音频的渠道。
splitChannelsOptionsobject{}Split channel options. Only applied when splitChannels=true. See below for options分割通道选项。仅当splitChannels=true时应用。参见下面的选项
splitChannelsOptions.overlaybooleanfalseOverlay waveforms for channels instead of rendering them on separate rows为通道叠加波形,而不是在单独的行上呈现它们
splitChannelsOptions.relativeNormalizationbooleanfalseNormalization maintains proportionality between channels. Only applies when normalize=true正常化保持了通道之间的比例。仅适用于normalize=true时
splitChannelsOptions.filterChannelsarray[]List of channel numbers to be excluded from rendered waveforms. Channels are 0-indexed要从呈现波形中排除的通道号列表。通道为0-indexed
splitChannelsOptions.channelColorsobject{}Overrides color per channel. Each key indicates a channel number and the corresponding value is an object describing it’s color porperties. For example: channelColors={ 0: { progressColor: ‘green’, waveColor: ‘pink’ }, 1: { progressColor: ‘orange’, waveColor: ‘purple’ } }覆盖每个通道的颜色。每个键表示一个通道号,对应的值是一个描述其颜色属性的对象。例如:channelColors={0: {progressColor: ‘绿色’,waveColor: ‘粉红色’},1:{progressColor: ‘橙色’,waveColor: ‘紫色’}}
waveColorstring#999The fill color of the waveform after the cursor.光标后波形的填充颜色。
xhrObject{}XHR options. For example: let xhr = { cache: ‘default’, mode: ‘cors’, method: ‘GET’, credentials: ‘same-origin’, redirect: ‘follow’, referrer: ‘client’, headers: [ { key: ‘Authorization’, value: ‘my-token’ } ]};XHR选项。例如:let xhr ={ cache: ‘default’, mode: ‘cors’, method: ‘GET’, credentials: ‘same-origin’, redirect: ‘follow’, referrer: ‘client’, headers: [ { key: ‘Authorization’, value: ‘my-token’ } ]}; XHR选项。例如:let xhr = {cache: ’ default ', mode: ’ cors ', method: ’ GET ‘,凭证:’ same-origin ‘,重定向:’ follow ', referrer: ’ client ', headers: [{key: ’ Authorization ', value: ’

方法介绍

cancelAjax() -取消音频文件加载过程。
destroy()-删除事件,元素和断开Web音频节点。
drawBuffer()-获取当前波视图的正确峰值并渲染波。
empty() -清除波形,如果零长度音频加载。
getActivePlugins()返回当前初始化的插件名称映射。
getBackgroundColor() -返回波形容器的背景色。
getcurrentTime() -以秒为单位返回当前进度。
getcursorcolor() -返回指针的填充颜色,表示播放头位置。
getDuration()-以秒为单位返回音频剪辑的持续时间。
getPlaybackRate() -返回音频剪辑的播放速度。
getProgresscolor()-返回光标后面波形的填充颜色。
getVolume()-返回当前音频剪辑的音量。
getMute()-返回当前静音状态。
getFilters()-返回当前集合过滤器的数组。
getwaveColor()-返回光标后波形的填充颜色。
exportPcM(length, accuracy, nowindow, start) -将PCM数据导出到JsoN数组中。可选参数length [number]—default: 124, accuracy [number]—default: 1eeee, nowindow [true false]—default: false, start [number]—default: eexportImage(格式,质量,类型)-返回波形图像作为数据URl或Blob。
isPlaying() -如果正在播放则返回true,否则返回false。加载(url,峰值,preload) -从url通过XHR加载音频。可选的峰值数组。可选预加载参数none metadata auto],如果使用后端MediaElement,则传递给Audio元素。
loadBlob(url) -从Blob或File对象加载音频。
on(eventName,callback)-订阅一个事件。有关所有事件的列表,请参见WaveSurfer事件。
un(eventName, callback)-取消订阅事件。
unAll() -取消订阅所有事件。
pause()-停止播放。
play(start, end]])-从当前位置开始播放。可选的开始和结束测量秒可用于设置音频播放的范围。
playPause()-暂停时播放,播放时暂停。
seekAndCenter(progress)-寻求进度和中心视图[e.]](开始,结束)。
seekTo(progress)-寻求一个进展[e.]1](0开始,1结束)。
setBackgroundcolor(color)-设置波形容器的背景色。
setCursorColor(color) -设置指针的填充颜色,表示播放头位置。
setHeight (height)-设置波形的高度。
setFilter (filters)-用于将您自己的WebAudio节点插入到图中。参见下面的连接过滤器。setPlaybackRate(rate) -设置播放速度(e.s是半速度,是正常速度,是两倍速度,等等)。setPlayEnd(position)-设置播放停止的点,以秒为单位。
setVolume (newvolume) -设置播放音量为一个新值[e…]] (o沉默,最大1个)。
setMute(mute)-静音当前声音。
setProgresscolor(color) -设置光标后面波形的填充颜色。
setwavecolor(color) -设置光标后波形的填充颜色。
skip(offset)-从当前位置跳过若干秒(使用负值向后走)。
skipBackward()-倒带skipLength秒。
skipForward() -跳过skipLength秒。
setSinkId(deviceld)-设置接收器id来改变音频输出设备。
stop()-停止并返回起点。
toggleMute()-打开和关闭音量。
toggleInteraction()-切换鼠标交互。
toggleScroll()-切换scrollParent。
zoom(pxPersec) -水平缩放波形。该参数是音频每秒的水平像素数。它还更改参数minPxPersec并启用scrollParent选项。

事件介绍

  1. 你可以使用on()和un()方法来订阅和取消订阅各种播放器事件。例如:
wavesurfer.on('pause', function () {
    wavesurfer.params.container.style.opacity = 0.9;
});
  1. 以下为可使用事件
    audioprocess -在音频播放时连续触发。
    dblclick-当双击实例时。
    destroy-实例被销毁。
    error-在错误时发生。回调将收到(字符串)错误消息。
    finish -当它结束播放时。相互作用-当与波形相互作用时。
    loading-连续触发加载时使用获取或拖放。回调将接收(整数)加载进度百分比o…oo]。
    mute-静音改变。回调将接收(boolean)新的静音状态。
    pause-当音频暂停时。
    play-播放开始时。
    ready-当音频加载,解码和波形绘制。当使用MediaElement时,它在绘制波形之前触发,请参见就绪波形。
    scroll-当滚动条被移动时。回调将接收一个ScrollEvent对象。
    seek-寻找。回调将接收(float)进度[e…1]。
    volume-音量变化。回调将接收(整数)新卷。
    waveform-ready-在使用MediaElement后端绘制波形后触发。如果你正在使用WebAudio后端,你可以使用ready。
    zoom- 放大。回调将接收(整数)minPxPerSec。

使用

  1. 安装
    npm i wavesurfer.js -S;
  2. 使用
<div id="waveform"></div>
import WaveSurfer from 'wavesurfer.js'
const init = () => {
    let wavesurfer = WaveSurfer.create({
      // 需要的容器盒子
      container: '#waveform',
      // 是否出现滚动条
      scrollParent: true,
      // 播放进行时线条颜色
      cursorColor: '#fff',
      // 播放进行时线条宽度
      cursorWidth: 2,
      // 未播放的波纹颜色
      waveColor: 'transparent',
      // 已播放的波纹颜色
      progressColor: 'blue',
      // 倍速
      audioRate: 1,
      height: 639
    });
    // 加载音频文件
    wavesurfer.load('/audio/gg.mp3');
    wavesurfer.on('ready', function () {
      wavesurfer.play();
    });
 }
 init();

图例

在这里插入图片描述

音频资料

  1. 测试音频为 国歌 。(音乐软件可免费下载)

参考资料

  1. wavesurfer.js官网
  2. 点击去查看wavesurfer-js的API

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/135693.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

挺进2023 年的JavaScript 框架

瞥见未来的美妙之处在于&#xff0c;道路永远不会完全清晰。我们可以观察趋势&#xff0c;观察创新并尝试规划路线。更好的是&#xff0c;我们可以成为这些创新的一部分来指导方向。但没有什么是确定的。 2022 年发布了大量推动 Web 开发的重大版本。我们看到了 Astro 和 Svel…

Jetson NX + yolov5 v5.0 + TensorRT加速+调用usb摄像头

上一篇笔记记录了如何使用yolov5使用usb摄像头使用权重进行测试,测试效果如下 本篇文章具体操作步骤如下就可以了&#xff0c;切记版本要对应 &#xff0c;我产生这个错误的原因就是版本问题&#xff0c;成功转换但是还是卡顿&#xff0c;估计是硬件usb问题&#xff0c;加速以后…

2023年最值得学习的10大编程语言

作为一名程序员&#xff0c;我们的目标之一就是学习新技术和编程语言&#xff0c;但是你应该学习哪些语言呢&#xff1f;由于学习一门编程语言既需要时间又需要耐心&#xff0c;因此您应该学习一门值得付出努力的语言&#xff1b;我的意思是&#xff0c;它可以帮助你获得更好的…

2023前端必会手写面试题整理

实现一个compose函数 组合多个函数&#xff0c;从右到左&#xff0c;比如&#xff1a;compose(f, g, h) 最终得到这个结果 (...args) > f(g(h(...args))). 题目描述:实现一个 compose 函数 // 用法如下: function fn1(x) {return x 1; } function fn2(x) {return x 2; } …

UTF-8编码

阅读该文章之前&#xff0c;请阅读以下两篇文章&#xff0c;了解GBK编码和Unicode编码&#xff1a; GBK编码的理解_sgmcy的博客-CSDN博客 Unicode编码的理解_sgmcy的博客-CSDN博客 UTF的意思是&#xff1a;Unicode Transformation Format 。也就是Unicode 转换格式。可见&am…

python初级教程七 JSON 数据解析

JSON 数据解析 JSON (JavaScript Object Notation) 是一种轻量级的数据交换格式。 Python3 中可以使用 json 模块来对 JSON 数据进行编解码&#xff0c;它包含了两个函数&#xff1a; json.dumps(): 对数据进行编码。 json.loads(): 对数据进行解码。 在 json 的编解码过程…

【数据结构】C语言实现双链表

目录 前言 双链表节点定义 接口函数实现 初始化函数 创建节点 打印双链表 尾插节点 尾删节点 头插节点 头删节点 指定位置前插入 删除指定位置节点 改写插入删除 判断链表是否为空 计算链表长度 销毁链表 双链表完整代码 浅谈链表及顺序表 前言 前面我们已经实…

Speed and Memory Efficient Dense RGB-D SLAM in Dynamic Scenes论文笔记

Speed and Memory Efficient Dense RGB-D SLAM in Dynamic Scenes论文笔记 论文中的主要引用文献&#xff1a; [7:A coarse and relevant 3d representation for fast and lightweight rgb-d mapping] 超表元建图 [14: Fast optical flow using dense inverse search] 稠密光流…

后端Web开发框架(Java)

为什么使用Spring Boot 简化配置&#xff0c;无需编写太多的 xml 配置文件&#xff0c;效率很高&#xff1b;Spring 可以整合很多各式各样的框架&#xff0c;并能很好的集成&#xff1b;基于 Spring 构建&#xff0c;使开发者快速入门&#xff0c;门槛很低&#xff1b;Spring …

LabVIEW调用自己写的DLL

首先&#xff0c;我用的LabVIEW是8.5版本的&#xff0c;比较老但工作需要 先新建VI 程序框图中选择 互连接口 - 库与可执行程序 选择 调用库函数… 拖到面板 并右击它 选择配置 在库名或路径中选择写好的DLL方案中的DEBUG中dll文件 确定以后就要选择哪个函数&#xff0c;并…

【数字图像处理】毛笔字细化

源码链接&#xff1a;calligraphy.cpp 一、实验要求 附件是书法毛笔字&#xff0c;请将附件图片中“年少有为”四个字进行笔画细化。 二、实验内容 首先观察图片&#xff0c;是只将黑色的毛笔字部分进行细化&#xff0c;所以需要先把印章这类的区域去除。先通过将图片转到h…

Content Security Policy (CSP) 介绍

内容安全策略 (CSP) 是一个额外的安全层&#xff0c;用于检测并削弱某些特定类型的攻击&#xff0c;包括跨站脚本 (XSS) 和数据注入攻击等。无论是数据盗取、网站内容污染还是散发恶意软件&#xff0c;这些攻击都是主要的手段。 起因 当我不经意间在 Twitter 页面 view source…

JavaScript 简单类型与复杂类型

JavaScript 简单类型与复杂类型 目录JavaScript 简单类型与复杂类型1. 简单类型与复杂类型2. 堆和栈3. 简单类型的内存分配4.复杂类型的内存分配5. 简单类型传参6. 复杂类型传参7.下面是代码1、Math对象最大值2. 封装自己的数学对象3. Math绝对值和三个取整方法4.Math对象获取随…

WebSocket实现聊天室

需求 实现用户登录功能展示用户好友列表功能实现用户历史消息展示实现单聊信息和群聊信息 效果展示 用户登录 好友列表展示 历史消息展示 聊天 代码实现 说明&#xff1a;Springboot项目&#xff0c;页面是用 thymeleaf 整合的。 maven依赖 <dependencies><depen…

π122E31兼容ISO7221CD 200Mbps高速率 双通道数字隔离器

π122E31兼容ISO7221CD 200Mbps高速率 双通道数字隔离器&#xff0c;具有出色的性能特征和可靠性&#xff0c;整体性能优于光耦和基于其他原理的数字隔离器产品。 产品传输通道间彼此独立&#xff0c;可实现多种传输方向的配置&#xff0c;可实现 3.0kVrms 隔离耐压等级和 DC 到…

MySQL数据库的安装与实现

MySQL在win系统中的安装 第1步&#xff1a;下载安装&#xff08;在windows系统中安装&#xff09; http://downloads.mysql.com/archives/community/ 我选择安装的是5.7.31&#xff0c;一般MySQL主要分为两个版本&#xff0c;一个是5.7系列&#xff0c;一个是5.8系列&#xf…

Linux 音频驱动

1 I.MX6ULL 开发板通过此接口外接了一个 WM8960 音频 DAC 芯片。 2 在信号处理领域&#xff0c;外界的声音是模拟信号&#xff0c;处理器能理解的是数字信号&#xff0c;因此这里就涉及到一个模拟信号转换为数字信号的过程&#xff0c;而完成这个功能的就是 ADC 芯片。 如果处…

MySQL的锁

把那些可能会被多个线程同时操作的资源称为临界资源&#xff0c;加锁的目的就是让这些临界资源在同一时刻只能有一个线程可以访问。数据库作为用户共享的一个资源&#xff0c;如何保证数据并发访问一致性也是所有数据库必须解决的问题&#xff0c;如何加锁是数据库并发访问性能…

字节前端高频手写面试题(持续更新中)

Promise // 模拟实现Promise // Promise利用三大手段解决回调地狱&#xff1a; // 1. 回调函数延迟绑定 // 2. 返回值穿透 // 3. 错误冒泡// 定义三种状态 const PENDING PENDING; // 进行中 const FULFILLED FULFILLED; // 已成功 const REJECTED REJECTED; // 已…

Vite构建工具

什么是构建工具&#xff1a;打包:将我们写的浏览器不认识的代码交给构建工具进行编译处理的过程就叫做打包&#xff0c;打包完成以后会给我们一个浏览器可以认识的文件 一个构建工具他到底承担了哪些脏活累活: 1. 模块化开发支持:支持直接从node_modules里引入代码&#xff0b…