diff --git a/components/kaburi.jsx b/components/kaburi.jsx
new file mode 100644
index 0000000..a395238
--- /dev/null
+++ b/components/kaburi.jsx
@@ -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 (
+
+ - かぶり回数
+ - {count}
+ - かぶり時間 (ms)
+ - {time}
+
+ );
+ }
+}
diff --git a/components/vad.jsx b/components/vad.jsx
index 7c6f355..241f7f6 100644
--- a/components/vad.jsx
+++ b/components/vad.jsx
@@ -1,5 +1,6 @@
import { Component } from "react";
import * as _VAD from "vad.js/lib/vad.js";
+import Kaburi from "./kaburi";
export default class extends Component {
state = {
@@ -25,6 +26,21 @@ export default class extends Component {
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 => {
this.setState({ audioStream: stream });
audioContext.createMediaStreamSource(stream).connect(splitter);
@@ -32,6 +48,8 @@ export default class extends Component {
VAD.bind({})({
source: leftNode,
voice_stop: () => {
+ putKaburi();
+
this.setState({
left: null,
activity: [
@@ -52,6 +70,8 @@ export default class extends Component {
VAD.bind({})({
source: rightNode,
voice_stop: () => {
+ putKaburi();
+
this.setState({
right: null,
activity: [
@@ -89,11 +109,7 @@ export default class extends Component {
右
{this.state.right && "発話中..."}
-
- {this.state.activity.map((l, i) => (
- - {JSON.stringify(l)}
- ))}
-
+
);
}