Kaynağa Gözat

fix(ts) adjust syntax so TSC doesn't complain

Emitting declarations generated these errors:

~~~~
modules/transcription/audioRecorder.js:3:1 - error TS9005: Declaration emit for this file requires using private name 'TrackRecorder'. An explicit type annotation may unblock declaration emit.

3 const RecordingResult = require('./recordingResult');
  ~~~~~

modules/transcription/recordingResult.js:13:1 - error TS9005: Declaration emit for this file requires using private name 'RecordingResult'. An explicit type annotation may unblock declaration emit.

13 const RecordingResult = function(blob, name, startTime, wordArray) {
   ~~~~~

modules/transcription/transcriber.js:1:1 - error TS9006: Declaration emit for this file requires using private name 'SphinxService' from module '"/Users/saghul/work/jitsi/lib-jitsi-meet/modules/transcription/transcriptionServices/SphinxTranscriptionService"'. An explicit type annotation may unblock declaration emit.

1 const AudioRecorder = require('./audioRecorder');
  ~~~~~

modules/transcription/word.js:7:1 - error TS9005: Declaration emit for this file requires using private name 'Word'. An explicit type annotation may unblock declaration emit.

7 const Word = function(word, begin, end) {
  ~~~~~

Found 4 errors.
~~~~
dev1
Saúl Ibarra Corretgé 3 yıl önce
ebeveyn
işleme
be6830a9bc

+ 3
- 26
modules/transcription/audioRecorder.js Dosyayı Görüntüle

@@ -1,4 +1,5 @@
1
-const RecordingResult = require('./recordingResult');
1
+import RecordingResult from './recordingResult';
2
+import TrackRecorder from './trackRecorder';
2 3
 
3 4
 /**
4 5
  * Possible audio formats MIME types
@@ -6,30 +7,6 @@ const RecordingResult = require('./recordingResult');
6 7
 const AUDIO_WEBM = 'audio/webm'; // Supported in chrome
7 8
 const AUDIO_OGG = 'audio/ogg'; // Supported in firefox
8 9
 
9
-/**
10
- * A TrackRecorder object holds all the information needed for recording a
11
- * single JitsiTrack (either remote or local)
12
- * @param track The JitsiTrack the object is going to hold
13
- */
14
-const TrackRecorder = function(track) {
15
-    // The JitsiTrack holding the stream
16
-    this.track = track;
17
-
18
-    // The MediaRecorder recording the stream
19
-    this.recorder = null;
20
-
21
-    // The array of data chunks recorded from the stream
22
-    // acts as a buffer until the data is stored on disk
23
-    this.data = null;
24
-
25
-    // the name of the person of the JitsiTrack. This can be undefined and/or
26
-    // not unique
27
-    this.name = null;
28
-
29
-    // the time of the start of the recording
30
-    this.startTime = null;
31
-};
32
-
33 10
 /**
34 11
  * Starts the recording of a JitsiTrack in a TrackRecorder object.
35 12
  * This will also define the timestamp and try to update the name
@@ -301,4 +278,4 @@ AudioRecorder.prototype.getFileType = function() {
301 278
 /**
302 279
  * export the main object AudioRecorder
303 280
  */
304
-module.exports = AudioRecorder;
281
+export default AudioRecorder;

+ 14
- 15
modules/transcription/recordingResult.js Dosyayı Görüntüle

@@ -4,19 +4,18 @@
4 4
  * This object stores variables needed around the recording of an audio stream
5 5
  * and passing this recording along with additional information along to
6 6
  * different processes
7
- * @param blob the recording audio stream as a single blob
8
- * @param name the name of the person of the audio stream
9
- * @param startTime the time in UTC when recording of the audiostream started
10
- * @param wordArray the recorder audio stream transcribed as an array of Word
11
- *                  objects
12 7
  */
13
-const RecordingResult = function(blob, name, startTime, wordArray) {
14
-    this.blob = blob;
15
-    this.name = name;
16
-    this.startTime = startTime;
17
-    this.wordArray = wordArray;
18
-};
19
-
20
-/* eslint-enable max-params */
21
-
22
-module.exports = RecordingResult;
8
+export default class RecordingResult {
9
+    /**
10
+     * @param blob the recording audio stream as a single blob
11
+     * @param name the name of the person of the audio stream
12
+     * @param startTime the time in UTC when recording of the audiostream started
13
+     * @param wordArray the recorder audio stream transcribed as an array of Word objects
14
+     */
15
+    constructor(blob, name, startTime, wordArray) {
16
+        this.blob = blob;
17
+        this.name = name;
18
+        this.startTime = startTime;
19
+        this.wordArray = wordArray;
20
+    }
21
+}

+ 28
- 0
modules/transcription/trackRecorder.js Dosyayı Görüntüle

@@ -0,0 +1,28 @@
1
+/**
2
+ * A TrackRecorder object holds all the information needed for recording a
3
+ * single JitsiTrack (either remote or local)
4
+ * @param track The JitsiTrack the object is going to hold
5
+ */
6
+export default class TrackRecorder {
7
+    /**
8
+     * @param track The JitsiTrack the object is going to hold
9
+     */
10
+    constructor(track) {
11
+        // The JitsiTrack holding the stream
12
+        this.track = track;
13
+
14
+        // The MediaRecorder recording the stream
15
+        this.recorder = null;
16
+
17
+        // The array of data chunks recorded from the stream
18
+        // acts as a buffer until the data is stored on disk
19
+        this.data = null;
20
+
21
+        // the name of the person of the JitsiTrack. This can be undefined and/or
22
+        // not unique
23
+        this.name = null;
24
+
25
+        // the time of the start of the recording
26
+        this.startTime = null;
27
+    }
28
+}

+ 3
- 4
modules/transcription/transcriber.js Dosyayı Görüntüle

@@ -1,6 +1,5 @@
1
-const AudioRecorder = require('./audioRecorder');
2
-const SphinxService = require(
3
-    './transcriptionServices/SphinxTranscriptionService');
1
+import AudioRecorder from './audioRecorder';
2
+import SphinxService from './transcriptionServices/SphinxTranscriptionService';
4 3
 
5 4
 const BEFORE_STATE = 'before';
6 5
 const RECORDING_STATE = 'recording';
@@ -357,4 +356,4 @@ Transcriber.prototype.reset = function() {
357 356
     this.lineLength = 0;
358 357
 };
359 358
 
360
-module.exports = Transcriber;
359
+export default Transcriber;

+ 68
- 68
modules/transcription/transcriptionServices/AbstractTranscriptionService.js Dosyayı Görüntüle

@@ -2,75 +2,75 @@
2 2
  * Abstract class representing an interface to implement a speech-to-text
3 3
  * service on.
4 4
  */
5
-const TranscriptionService = function() {
6
-    throw new Error('TranscriptionService is abstract and cannot be'
7
-        + 'created');
8
-};
5
+export default class TranscriptionService {
6
+    /**
7
+     * Abstract class representing an interface to implement a speech-to-text
8
+     * service on.
9
+     */
10
+    constructor() {
11
+        throw new Error('TranscriptionService is abstract and cannot be created');
12
+    }
9 13
 
10
-/**
11
- * This method can be used to send the recorder audio stream and
12
- * retrieve the answer from the transcription service from the callback
13
- *
14
- * @param {RecordingResult} recordingResult a recordingResult object which
15
- * includes the recorded audio stream as a blob
16
- * @param {Function} callback  which will retrieve the a RecordingResult with
17
- *        the answer as a WordArray
18
- */
19
-TranscriptionService.prototype.send = function send(recordingResult, callback) {
20
-    this.sendRequest(recordingResult.blob, response => {
21
-        if (this.verify(response)) {
22
-            recordingResult.wordArray = this.formatResponse(response);
23
-        } else {
24
-            console.log('the retrieved response from the server is not valid!');
25
-            recordingResult.wordArray = [];
26
-        }
27
-        callback(recordingResult);
28
-    });
29
-};
14
+    /**
15
+     * This method can be used to send the recorder audio stream and
16
+     * retrieve the answer from the transcription service from the callback
17
+     *
18
+     * @param {RecordingResult} recordingResult a recordingResult object which
19
+     * includes the recorded audio stream as a blob
20
+     * @param {Function} callback  which will retrieve the a RecordingResult with
21
+     *        the answer as a WordArray
22
+     */
23
+    send(recordingResult, callback) {
24
+        this.sendRequest(recordingResult.blob, response => {
25
+            if (this.verify(response)) {
26
+                recordingResult.wordArray = this.formatResponse(response);
27
+            } else {
28
+                console.log('the retrieved response from the server is not valid!');
29
+                recordingResult.wordArray = [];
30
+            }
31
+            callback(recordingResult);
32
+        });
33
+    }
30 34
 
31
-/**
32
- * Abstract method which will rend the recorder audio stream to the implemented
33
- * transcription service and will retrieve an answer, which will be
34
- * called on the given callback method
35
- *
36
- * @param {Blob} audioBlob the recorded audio stream as a single Blob
37
- * @param {function} callback function which will retrieve the answer
38
- *                            from the service
39
- */
40
-// eslint-disable-next-line no-unused-vars
41
-TranscriptionService.prototype.sendRequest = function(audioBlob, callback) {
42
-    throw new Error('TranscriptionService.sendRequest is abstract');
43
-};
35
+    /**
36
+     * Abstract method which will rend the recorder audio stream to the implemented
37
+     * transcription service and will retrieve an answer, which will be
38
+     * called on the given callback method
39
+     *
40
+     * @param {Blob} audioBlob the recorded audio stream as a single Blob
41
+     * @param {function} callback function which will retrieve the answer
42
+     *                            from the service
43
+     */
44
+    sendRequest(audioBlob, callback) { // eslint-disable-line no-unused-vars
45
+        throw new Error('TranscriptionService.sendRequest is abstract');
46
+    }
44 47
 
45
-/**
46
- * Abstract method which will parse the output from the implemented
47
- * transcription service to the expected format
48
- *
49
- * The transcriber class expect an array of word objects, where each word
50
- * object is one transcribed word by the service.
51
- *
52
- * The expected output of this method is an array of word objects, in
53
- * the correct order. That is, the first object in the array is the first word
54
- * being said, and the last word in the array is the last word being said
55
- *
56
- * @param response the answer from the speech-to-text server which needs to be
57
- *                 formatted
58
- * @return {Array<Word>} an array of Word objects
59
- */
60
-// eslint-disable-next-line no-unused-vars
61
-TranscriptionService.prototype.formatResponse = function(response) {
62
-    throw new Error('TranscriptionService.format is abstract');
63
-};
64
-
65
-/**
66
- * Abstract method which will verify that the response from the server is valid
67
- *
68
- * @param response the response from the server
69
- * @return {boolean} true if response is valid, false otherwise
70
- */
71
-// eslint-disable-next-line no-unused-vars
72
-TranscriptionService.prototype.verify = function(response) {
73
-    throw new Error('TranscriptionService.verify is abstract');
74
-};
48
+    /**
49
+     * Abstract method which will parse the output from the implemented
50
+     * transcription service to the expected format
51
+     *
52
+     * The transcriber class expect an array of word objects, where each word
53
+     * object is one transcribed word by the service.
54
+     *
55
+     * The expected output of this method is an array of word objects, in
56
+     * the correct order. That is, the first object in the array is the first word
57
+     * being said, and the last word in the array is the last word being said
58
+     *
59
+     * @param response the answer from the speech-to-text server which needs to be
60
+     *                 formatted
61
+     * @return {Array<Word>} an array of Word objects
62
+     */
63
+    formatResponse(response) { // eslint-disable-line no-unused-vars
64
+        throw new Error('TranscriptionService.format is abstract');
65
+    }
75 66
 
76
-module.exports = TranscriptionService;
67
+    /**
68
+     * Abstract method which will verify that the response from the server is valid
69
+     *
70
+     * @param response the response from the server
71
+     * @return {boolean} true if response is valid, false otherwise
72
+     */
73
+    verify(response) { // eslint-disable-line no-unused-vars
74
+        throw new Error('TranscriptionService.verify is abstract');
75
+    }
76
+}

+ 92
- 100
modules/transcription/transcriptionServices/SphinxTranscriptionService.js Dosyayı Görüntüle

@@ -1,121 +1,115 @@
1 1
 /* global config */
2 2
 
3
-const Word = require('../word');
3
+import Word from '../word';
4 4
 
5
-const audioRecorder = require('./../audioRecorder');
6
-const TranscriptionService = require('./AbstractTranscriptionService');
5
+import audioRecorder from './../audioRecorder';
6
+import AbstractTranscriptionService from './AbstractTranscriptionService';
7 7
 
8 8
 /**
9 9
  * Implements a TranscriptionService for a Sphinx4 http server
10 10
  */
11
-const SphinxService = function() {
12
-    // set the correct url
13
-    this.url = getURL();
14
-};
15
-
16
-/**
17
- * Subclass of AbstractTranscriptionService
18
- */
19
-SphinxService.prototype = Object.create(TranscriptionService.prototype);
20
-
21
-/**
22
- * Set the right constructor
23
- */
24
-SphinxService.constructor = SphinxService;
25
-
26
-/**
27
- * Overrides the sendRequest method from AbstractTranscriptionService
28
- * it will send the audio stream the a Sphinx4 server to get the transcription
29
- *
30
- * @param audioFileBlob the recorder audio stream an a single Blob
31
- * @param callback the callback function retrieving the server response
32
- */
33
-SphinxService.prototype.sendRequest = function(audioFileBlob, callback) {
34
-    console.log(`sending an audio file  to ${this.url}`);
35
-    console.log(`the audio file being sent: ${audioFileBlob}`);
36
-    const request = new XMLHttpRequest();
37
-
38
-    request.onreadystatechange = function() {
39
-        if (request.readyState === XMLHttpRequest.DONE
40
-            && request.status === 200) {
41
-            callback(request.responseText);
42
-        } else if (request.readyState === XMLHttpRequest.DONE) {
43
-            throw new Error(
44
-                `unable to accept response from sphinx server. status: ${
45
-                    request.status}`);
46
-        }
47
-
48
-        // if not ready no point to throw an error
49
-    };
50
-    request.open('POST', this.url);
51
-    request.setRequestHeader('Content-Type',
52
-        audioRecorder.determineCorrectFileType());
53
-    request.send(audioFileBlob);
54
-    console.log(`send ${audioFileBlob}`);
55
-};
56
-
57
-/**
58
- * Overrides the formatResponse method from AbstractTranscriptionService
59
- * It will parse the answer from the server in the expected format
60
- *
61
- * @param response the JSON body retrieved from the Sphinx4 server
62
- */
63
-SphinxService.prototype.formatResponse = function(response) {
64
-    const result = JSON.parse(response).objects;
65
-
66
-    // make sure to delete the session id object, which is always
67
-    // the first value in the JSON array
11
+export default class SphinxService extends AbstractTranscriptionService {
12
+    /**
13
+     * Implements a TranscriptionService for a Sphinx4 http server
14
+     */
15
+    constructor() {
16
+        super();
17
+
18
+        // set the correct url
19
+        this.url = getURL();
20
+    }
68 21
 
69
-    result.shift();
70
-    const array = [];
22
+    /**
23
+     * Overrides the sendRequest method from AbstractTranscriptionService
24
+     * it will send the audio stream the a Sphinx4 server to get the transcription
25
+     *
26
+     * @param audioFileBlob the recorder audio stream an a single Blob
27
+     * @param callback the callback function retrieving the server response
28
+     */
29
+    sendRequest(audioFileBlob, callback) {
30
+        console.log(`sending an audio file  to ${this.url}`);
31
+        console.log(`the audio file being sent: ${audioFileBlob}`);
32
+        const request = new XMLHttpRequest();
33
+
34
+        request.onreadystatechange = function() {
35
+            if (request.readyState === XMLHttpRequest.DONE
36
+                && request.status === 200) {
37
+                callback(request.responseText);
38
+            } else if (request.readyState === XMLHttpRequest.DONE) {
39
+                throw new Error(
40
+                    `unable to accept response from sphinx server. status: ${request.status}`);
41
+            }
42
+
43
+            // if not ready no point to throw an error
44
+        };
45
+        request.open('POST', this.url);
46
+        request.setRequestHeader('Content-Type',
47
+            audioRecorder.determineCorrectFileType());
48
+        request.send(audioFileBlob);
49
+        console.log(`send ${audioFileBlob}`);
50
+    }
71 51
 
72
-    result.forEach(
73
-        word =>
74
-            word.filler
52
+    /**
53
+     * Overrides the formatResponse method from AbstractTranscriptionService
54
+     * It will parse the answer from the server in the expected format
55
+     *
56
+     * @param response the JSON body retrieved from the Sphinx4 server
57
+     */
58
+    formatResponse(response) {
59
+        const result = JSON.parse(response).objects;
60
+
61
+        // make sure to delete the session id object, which is always
62
+        // the first value in the JSON array
63
+        result.shift();
64
+        const array = [];
65
+
66
+        result.forEach(
67
+            word => word.filler
75 68
                 || array.push(new Word(word.word, word.start, word.end)));
76 69
 
77
-    return array;
78
-};
70
+        return array;
71
+    }
79 72
 
80
-/**
81
- * checks wether the reply is empty, or doesn't contain a correct JSON object
82
- * @param response the server response
83
- * @return {boolean} whether the response is valid
84
- */
85
-SphinxService.prototype.verify = function(response) {
86
-    console.log(`response from server:${response.toString()}`);
73
+    /**
74
+     * checks wether the reply is empty, or doesn't contain a correct JSON object
75
+     * @param response the server response
76
+     * @return {boolean} whether the response is valid
77
+     */
78
+    verify(response) {
79
+        console.log(`response from server:${response.toString()}`);
80
+
81
+        // test if server responded with a string object
82
+        if (typeof response !== 'string') {
83
+            return false;
84
+        }
87 85
 
88
-    // test if server responded with a string object
89
-    if (typeof response !== 'string') {
90
-        return false;
91
-    }
86
+        // test if the string can be parsed into valid JSON
87
+        let json;
92 88
 
93
-    // test if the string can be parsed into valid JSON
94
-    let json;
89
+        try {
90
+            json = JSON.parse(response);
91
+        } catch (error) {
92
+            console.log(error);
95 93
 
96
-    try {
97
-        json = JSON.parse(response);
98
-    } catch (error) {
99
-        console.log(error);
94
+            return false;
95
+        }
100 96
 
101
-        return false;
102
-    }
97
+        // check if the JSON has a "objects" value
98
+        if (json.objects === undefined) {
99
+            return false;
100
+        }
103 101
 
104
-    // check if the JSON has a "objects" value
105
-    if (json.objects === undefined) {
106
-        return false;
107
-    }
102
+        // get the "objects" value and check for a session ID
103
+        const array = json.objects;
108 104
 
109
-    // get the "objects" value and check for a session ID
110
-    const array = json.objects;
105
+        if (!(array[0] && array[0]['session-id'])) {
106
+            return false;
107
+        }
111 108
 
112
-    if (!(array[0] && array[0]['session-id'])) {
113
-        return false;
109
+        // everything seems to be in order
110
+        return true;
114 111
     }
115
-
116
-    // everything seems to be in order
117
-    return true;
118
-};
112
+}
119 113
 
120 114
 /**
121 115
  * Gets the URL to the Sphinx4 server from the config file. If it's not there,
@@ -138,5 +132,3 @@ function getURL() {
138 132
 
139 133
     }
140 134
 }
141
-
142
-module.exports = SphinxService;

+ 33
- 28
modules/transcription/word.js Dosyayı Görüntüle

@@ -4,34 +4,39 @@
4 4
  * @param begin the time the word was started being uttered
5 5
  * @param end the time the word stopped being uttered
6 6
  */
7
-const Word = function(word, begin, end) {
8
-    this.word = word;
9
-    this.begin = begin;
10
-    this.end = end;
11
-};
7
+export default class Word {
8
+    /**
9
+     * @param word the word
10
+     * @param begin the time the word was started being uttered
11
+     * @param end the time the word stopped being uttered
12
+     */
13
+    constructor(word, begin, end) {
14
+        this.word = word;
15
+        this.begin = begin;
16
+        this.end = end;
17
+    }
12 18
 
13
-/**
14
- * Get the string representation of the word
15
- * @returns {*} the word as a string
16
- */
17
-Word.prototype.getWord = function() {
18
-    return this.word;
19
-};
19
+    /**
20
+     * Get the string representation of the word
21
+     * @returns {*} the word as a string
22
+     */
23
+    getWord() {
24
+        return this.word;
25
+    }
20 26
 
21
-/**
22
- * Get the time the word started being uttered
23
- * @returns {*} the start time as an integer
24
- */
25
-Word.prototype.getBeginTime = function() {
26
-    return this.begin;
27
-};
28
-
29
-/**
30
- * Get the time the word stopped being uttered
31
- * @returns {*} the end time as an integer
32
- */
33
-Word.prototype.getEndTime = function() {
34
-    return this.end;
35
-};
27
+    /**
28
+     * Get the time the word started being uttered
29
+     * @returns {*} the start time as an integer
30
+     */
31
+    getBeginTime() {
32
+        return this.begin;
33
+    }
36 34
 
37
-module.exports = Word;
35
+    /**
36
+     * Get the time the word stopped being uttered
37
+     * @returns {*} the end time as an integer
38
+     */
39
+    getEndTime() {
40
+        return this.end;
41
+    }
42
+}

Loading…
İptal
Kaydet