(model?: tfl.Sequential, backgroundAndNoiseOnly = false)
| 59 | let tfLoadModelSpy: jasmine.Spy; |
| 60 | |
| 61 | function setUpFakes(model?: tfl.Sequential, backgroundAndNoiseOnly = false) { |
| 62 | const words = |
| 63 | backgroundAndNoiseOnly ? fakeWordsNoiseAndUnknownOnly : fakeWords; |
| 64 | const numWords = words.length; |
| 65 | tfLoadModelSpy = |
| 66 | spyOn(tfl, 'loadLayersModel').and.callFake((url: string) => { |
| 67 | if (model == null) { |
| 68 | model = tfl.sequential(); |
| 69 | model.add(tfl.layers.flatten( |
| 70 | {inputShape: [fakeNumFrames, fakeColumnTruncateLength, 1]})); |
| 71 | secondLastBaseDenseLayer = tfl.layers.dense({ |
| 72 | units: 4, |
| 73 | activation: 'relu', |
| 74 | kernelInitializer: 'leCunNormal' |
| 75 | }); |
| 76 | model.add(secondLastBaseDenseLayer); |
| 77 | model.add(tfl.layers.dense({ |
| 78 | units: numWords, |
| 79 | useBias: false, |
| 80 | kernelInitializer: 'leCunNormal', |
| 81 | activation: 'softmax' |
| 82 | })); |
| 83 | } |
| 84 | return model; |
| 85 | }); |
| 86 | spyOn(BrowserFftUtils, 'loadMetadataJson') |
| 87 | .and.callFake(async (url: string) => { |
| 88 | return {words}; |
| 89 | }); |
| 90 | |
| 91 | spyOn(BrowserFftUtils, 'getAudioContextConstructor') |
| 92 | .and.callFake(() => FakeAudioContext.createInstance); |
| 93 | spyOn(BrowserFftUtils, 'getAudioMediaStream') |
| 94 | .and.callFake(() => new FakeAudioMediaStream()); |
| 95 | } |
| 96 | |
| 97 | it('Constructor works', () => { |
| 98 | const recognizer = new BrowserFftSpeechCommandRecognizer(); |
no outgoing calls
no test coverage detected