|
1 | 1 | import React from "react";
|
2 |
| -import Recorder from "recorderjs"; |
| 2 | +import { audioInput } from "./AudioInput.jsx" |
3 | 3 |
|
4 | 4 | export default class VoiceRecorder extends React.Component {
|
5 | 5 | constructor(props){
|
6 | 6 | super(props);
|
7 |
| - this.startUserMedia = this.startUserMedia.bind(this); |
8 | 7 | this.startRecording = this.startRecording.bind(this);
|
9 | 8 | this.stopRecording = this.stopRecording.bind(this);
|
10 | 9 | }
|
11 | 10 |
|
12 |
| - componentDidMount(){ |
13 |
| - // webkit shim |
14 |
| - navigator.getUserMedia = navigator.getUserMedia || |
15 |
| - navigator.webkitGetUserMedia || |
16 |
| - navigator.mozGetUserMedia; |
17 |
| - |
18 |
| - if (navigator.getUserMedia) { |
19 |
| - navigator.getUserMedia( |
20 |
| - {"audio": { |
21 |
| - "mandatory": { |
22 |
| - "googEchoCancellation": "false", |
23 |
| - "googAutoGainControl": "false", |
24 |
| - "googNoiseSuppression": "false", |
25 |
| - "googHighpassFilter": "false" |
26 |
| - }, |
27 |
| - "optional": [] |
28 |
| - }}, |
29 |
| - this.startUserMedia, function(e) { |
30 |
| - console.log('No live audio input: ' + e); |
31 |
| - }); |
32 |
| - } else { |
33 |
| - console.log("getUserMedia not supported"); |
34 |
| - } |
35 |
| - } |
36 |
| - |
37 |
| - startUserMedia(stream) { |
38 |
| - let audioContext = new AudioContext; |
39 |
| - let input = audioContext.createMediaStreamSource(stream); |
40 |
| - console.log('Media stream created.'); |
41 |
| - |
42 |
| - this.recorder = new Recorder(input); |
43 |
| - console.log('Recorder initialised.'); |
44 |
| - } |
45 |
| - |
46 | 11 | startRecording() {
|
47 |
| - this.recorder && this.recorder.record(); |
48 |
| - console.log('Start recording...'); |
| 12 | + audioInput.record(); |
49 | 13 | }
|
50 | 14 |
|
51 | 15 | stopRecording(){
|
52 |
| - console.log('Stop recording...'); |
53 |
| - this.recorder && this.recorder.stop(); |
54 |
| - this.recorder.exportWAV(this.props.handleSpeech); |
55 |
| - this.recorder.clear(); |
| 16 | + audioInput.stopRecording(this.props.handleSpeech); |
56 | 17 | }
|
57 | 18 |
|
58 | 19 | render(){
|
|
0 commit comments