mirror of
https://github.com/kou029w/_.git
synced 2025-01-30 22:08:02 +00:00
feat: 発話区間を記録する
This commit is contained in:
parent
7376e7ae3a
commit
6197e1f0df
1 changed files with 44 additions and 17 deletions
|
@ -6,11 +6,11 @@ export default class extends Component {
|
||||||
audioContext: new AudioContext(),
|
audioContext: new AudioContext(),
|
||||||
audioStream: null,
|
audioStream: null,
|
||||||
left: null,
|
left: null,
|
||||||
right: null
|
right: null,
|
||||||
|
activity: []
|
||||||
};
|
};
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
const setState = this.setState.bind(this);
|
|
||||||
const audioContext = this.state.audioContext;
|
const audioContext = this.state.audioContext;
|
||||||
const leftNode = audioContext.createGain();
|
const leftNode = audioContext.createGain();
|
||||||
const rightNode = audioContext.createGain();
|
const rightNode = audioContext.createGain();
|
||||||
|
@ -26,26 +26,46 @@ export default class extends Component {
|
||||||
);
|
);
|
||||||
|
|
||||||
const start = stream => {
|
const start = stream => {
|
||||||
setState({ audioStream: stream });
|
this.setState({ audioStream: stream });
|
||||||
audioContext.createMediaStreamSource(stream).connect(splitter);
|
audioContext.createMediaStreamSource(stream).connect(splitter);
|
||||||
|
|
||||||
VAD.bind({})({
|
VAD.bind({})({
|
||||||
source: leftNode,
|
source: leftNode,
|
||||||
voice_stop() {
|
voice_stop: () => {
|
||||||
setState({ left: null });
|
this.setState({
|
||||||
|
left: null,
|
||||||
|
activity: [
|
||||||
|
...this.state.activity,
|
||||||
|
{
|
||||||
|
ch: "l",
|
||||||
|
startTime: this.state.left,
|
||||||
|
endTime: new Date().getTime()
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
},
|
},
|
||||||
voice_start() {
|
voice_start: () => {
|
||||||
setState({ left: "喋り始めました" });
|
this.setState({ left: new Date().getTime() });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
VAD.bind({})({
|
VAD.bind({})({
|
||||||
source: rightNode,
|
source: rightNode,
|
||||||
voice_stop() {
|
voice_stop: () => {
|
||||||
setState({ right: null });
|
this.setState({
|
||||||
|
right: null,
|
||||||
|
activity: [
|
||||||
|
...this.state.activity,
|
||||||
|
{
|
||||||
|
ch: "r",
|
||||||
|
startTime: this.state.right,
|
||||||
|
endTime: new Date().getTime()
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
},
|
},
|
||||||
voice_start() {
|
voice_start: () => {
|
||||||
setState({ right: "喋り始めました" });
|
this.setState({ right: new Date().getTime() });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -62,12 +82,19 @@ export default class extends Component {
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<dl>
|
<div>
|
||||||
<dt>左</dt>
|
<dl>
|
||||||
<dd>{this.state.left}</dd>
|
<dt>左</dt>
|
||||||
<dt>右</dt>
|
<dd>{this.state.left && "発話中..."}</dd>
|
||||||
<dd>{this.state.right}</dd>
|
<dt>右</dt>
|
||||||
</dl>
|
<dd>{this.state.right && "発話中..."}</dd>
|
||||||
|
</dl>
|
||||||
|
<ul>
|
||||||
|
{this.state.activity.map((l, i) => (
|
||||||
|
<li key={i}>{JSON.stringify(l)}</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue