mirror of
https://github.com/kou029w/_.git
synced 2025-01-30 13:58:08 +00:00
Add 'vad/' from commit 'f5983bb9bdb05001f6dea60cc4bae8fd81543cad'git-subtree-dir: vadgit-subtree-mainline: 90bb5008c5b86182598e908ac4d4374fac3149f8git-subtree-split: f5983bb9bd
This commit is contained in:
commit
bb126f221e
8 changed files with 5522 additions and 0 deletions
80
vad/.gitignore
vendored
Normal file
80
vad/.gitignore
vendored
Normal file
|
@ -0,0 +1,80 @@
|
|||
### https://raw.github.com/github/gitignore/4a8e0a151becd5ccbb83e4aca6e6c195f3d506fd/Node.gitignore
|
||||
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# TypeScript v1 declaration files
|
||||
typings/
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variables file
|
||||
.env
|
||||
|
||||
# parcel-bundler cache (https://parceljs.org/)
|
||||
.cache
|
||||
|
||||
# next.js build output
|
||||
.next
|
||||
|
||||
# nuxt.js build output
|
||||
.nuxt
|
||||
|
||||
# vuepress build output
|
||||
.vuepress/dist
|
||||
|
||||
# Serverless directories
|
||||
.serverless
|
||||
|
||||
# FuseBox cache
|
||||
.fusebox/
|
||||
|
||||
|
18
vad/README.md
Normal file
18
vad/README.md
Normal file
|
@ -0,0 +1,18 @@
|
|||
# VAD
|
||||
|
||||
- 音声検知
|
||||
- 左右の音声を検知します
|
||||
|
||||
## 前提条件
|
||||
|
||||
- Yarn
|
||||
|
||||
## 使い方
|
||||
|
||||
```sh
|
||||
# 依存モジュールをインストール
|
||||
yarn
|
||||
# アプリを起動
|
||||
yarn next
|
||||
# http://localhost:3000 にアクセスする
|
||||
```
|
15
vad/components/kaburi.jsx
Normal file
15
vad/components/kaburi.jsx
Normal file
|
@ -0,0 +1,15 @@
|
|||
export default ({ activity }) => {
|
||||
const count = activity.length;
|
||||
const time = activity
|
||||
.map(a => a.endTime - a.startTime)
|
||||
.reduce((a, c) => a + c, 0);
|
||||
|
||||
return (
|
||||
<dl>
|
||||
<dt>かぶり回数</dt>
|
||||
<dd>{count}</dd>
|
||||
<dt>かぶり時間 (ms)</dt>
|
||||
<dd>{time}</dd>
|
||||
</dl>
|
||||
);
|
||||
};
|
21
vad/components/percentage.jsx
Normal file
21
vad/components/percentage.jsx
Normal file
|
@ -0,0 +1,21 @@
|
|||
export default ({ activity }) => {
|
||||
const leftActivity = activity.filter(a => a.ch === "l"),
|
||||
rightActivity = activity.filter(a => a.ch === "r");
|
||||
const [l, r] = [leftActivity, rightActivity].map(activity => {
|
||||
return activity
|
||||
.map(a => a.endTime - a.startTime)
|
||||
.reduce((a, c) => a + c, 0);
|
||||
});
|
||||
const sum = l + r;
|
||||
|
||||
return (
|
||||
<dl>
|
||||
<dt>会話時間 (ms)</dt>
|
||||
<dd>{sum}</dd>
|
||||
<dt>会話の割合</dt>
|
||||
<dd>
|
||||
左 <meter value={l / sum}>{l / sum}</meter> 右
|
||||
</dd>
|
||||
</dl>
|
||||
);
|
||||
};
|
118
vad/components/vad.jsx
Normal file
118
vad/components/vad.jsx
Normal file
|
@ -0,0 +1,118 @@
|
|||
import { Component } from "react";
|
||||
import * as _VAD from "vad.js/lib/vad.js";
|
||||
import Percentage from "./percentage";
|
||||
import Kaburi from "./kaburi";
|
||||
|
||||
export default class extends Component {
|
||||
state = {
|
||||
audioContext: new AudioContext(),
|
||||
audioStream: null,
|
||||
left: null,
|
||||
right: null,
|
||||
activity: [],
|
||||
kaburiActivity: []
|
||||
};
|
||||
|
||||
componentDidMount() {
|
||||
const audioContext = this.state.audioContext;
|
||||
const leftNode = audioContext.createGain();
|
||||
const rightNode = audioContext.createGain();
|
||||
const splitter = audioContext.createChannelSplitter(2);
|
||||
|
||||
splitter.connect(
|
||||
leftNode,
|
||||
0
|
||||
);
|
||||
splitter.connect(
|
||||
rightNode,
|
||||
1
|
||||
);
|
||||
|
||||
const putKaburi = () => {
|
||||
if (this.state.left !== null && this.state.right !== null) {
|
||||
this.setState({
|
||||
kaburiActivity: [
|
||||
...this.state.kaburiActivity,
|
||||
{
|
||||
startTime: Math.max(this.state.left, this.state.right),
|
||||
endTime: new Date().getTime()
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const start = stream => {
|
||||
this.setState({ audioStream: stream });
|
||||
audioContext.createMediaStreamSource(stream).connect(splitter);
|
||||
|
||||
VAD.bind({})({
|
||||
source: leftNode,
|
||||
voice_stop: () => {
|
||||
putKaburi();
|
||||
|
||||
this.setState({
|
||||
left: null,
|
||||
activity: [
|
||||
...this.state.activity,
|
||||
{
|
||||
ch: "l",
|
||||
startTime: this.state.left,
|
||||
endTime: new Date().getTime()
|
||||
}
|
||||
]
|
||||
});
|
||||
},
|
||||
voice_start: () => {
|
||||
this.setState({ left: new Date().getTime() });
|
||||
}
|
||||
});
|
||||
|
||||
VAD.bind({})({
|
||||
source: rightNode,
|
||||
voice_stop: () => {
|
||||
putKaburi();
|
||||
|
||||
this.setState({
|
||||
right: null,
|
||||
activity: [
|
||||
...this.state.activity,
|
||||
{
|
||||
ch: "r",
|
||||
startTime: this.state.right,
|
||||
endTime: new Date().getTime()
|
||||
}
|
||||
]
|
||||
});
|
||||
},
|
||||
voice_start: () => {
|
||||
this.setState({ right: new Date().getTime() });
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
navigator.mediaDevices
|
||||
.getUserMedia({ audio: { echoCancellation: false } }) // モノラル防ぐ
|
||||
.then(start)
|
||||
.catch(console.error);
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
this.state.audioStream.getTracks().forEach(t => t.stop());
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div>
|
||||
<dl>
|
||||
<dt>左</dt>
|
||||
<dd>{this.state.left && "発話中..."}</dd>
|
||||
<dt>右</dt>
|
||||
<dd>{this.state.right && "発話中..."}</dd>
|
||||
</dl>
|
||||
<Percentage activity={this.state.activity} />
|
||||
<Kaburi activity={this.state.kaburiActivity} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
11
vad/package.json
Normal file
11
vad/package.json
Normal file
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"name": "vad",
|
||||
"version": "0.0.1",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"next": "^7.0.2",
|
||||
"react": "^16.6.3",
|
||||
"react-dom": "^16.6.3",
|
||||
"vad.js": "kdavis-mozilla/vad.js"
|
||||
}
|
||||
}
|
10
vad/pages/index.jsx
Normal file
10
vad/pages/index.jsx
Normal file
|
@ -0,0 +1,10 @@
|
|||
import React from "react";
|
||||
import dynamic from "next/dynamic";
|
||||
|
||||
const VAD = dynamic(() => import("../components/vad"), { ssr: false });
|
||||
|
||||
export default () => (
|
||||
<div>
|
||||
<VAD />
|
||||
</div>
|
||||
);
|
5249
vad/yarn.lock
Normal file
5249
vad/yarn.lock
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Reference in a new issue