1
0
Fork 0
mirror of https://github.com/kou029w/_.git synced 2025-01-31 06:18:07 +00:00

feat: かぶり回数, 時間表示機能追加

This commit is contained in:
kohei 2018-11-15 17:36:28 +09:00
parent 6197e1f0df
commit 5c28ad7fa0
2 changed files with 41 additions and 5 deletions

20
components/kaburi.jsx Normal file
View file

@ -0,0 +1,20 @@
import { Component } from "react";
export default class extends Component {
render() {
const activity = this.props.activity.filter(a => a.ch === "kaburi");
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>
);
}
}

View file

@ -1,5 +1,6 @@
import { Component } from "react"; import { Component } from "react";
import * as _VAD from "vad.js/lib/vad.js"; import * as _VAD from "vad.js/lib/vad.js";
import Kaburi from "./kaburi";
export default class extends Component { export default class extends Component {
state = { state = {
@ -25,6 +26,21 @@ export default class extends Component {
1 1
); );
const putKaburi = () => {
if (this.state.left !== null && this.state.right !== null) {
this.setState({
activity: [
...this.state.activity,
{
ch: "kaburi",
startTime: Math.max(this.state.left, this.state.right),
endTime: new Date().getTime()
}
]
});
}
};
const start = stream => { const start = stream => {
this.setState({ audioStream: stream }); this.setState({ audioStream: stream });
audioContext.createMediaStreamSource(stream).connect(splitter); audioContext.createMediaStreamSource(stream).connect(splitter);
@ -32,6 +48,8 @@ export default class extends Component {
VAD.bind({})({ VAD.bind({})({
source: leftNode, source: leftNode,
voice_stop: () => { voice_stop: () => {
putKaburi();
this.setState({ this.setState({
left: null, left: null,
activity: [ activity: [
@ -52,6 +70,8 @@ export default class extends Component {
VAD.bind({})({ VAD.bind({})({
source: rightNode, source: rightNode,
voice_stop: () => { voice_stop: () => {
putKaburi();
this.setState({ this.setState({
right: null, right: null,
activity: [ activity: [
@ -89,11 +109,7 @@ export default class extends Component {
<dt></dt> <dt></dt>
<dd>{this.state.right && "発話中..."}</dd> <dd>{this.state.right && "発話中..."}</dd>
</dl> </dl>
<ul> <Kaburi activity={this.state.activity} />
{this.state.activity.map((l, i) => (
<li key={i}>{JSON.stringify(l)}</li>
))}
</ul>
</div> </div>
); );
} }