mirror of
https://github.com/kou029w/_.git
synced 2025-01-30 22:08:02 +00:00
feat: かぶり回数, 時間表示機能追加
This commit is contained in:
parent
6197e1f0df
commit
5c28ad7fa0
2 changed files with 41 additions and 5 deletions
20
components/kaburi.jsx
Normal file
20
components/kaburi.jsx
Normal 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>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue