Skip to content

Commit fc4fd93

Browse files
committed
Update README.md
1 parent 9f3debb commit fc4fd93

File tree

1 file changed

+64
-7
lines changed

1 file changed

+64
-7
lines changed

README.md

Lines changed: 64 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,69 @@ Available modules:
1313
- Custom SEPIA VAD module using Meyda to analyze bark-scale, **MFCC** and more
1414
- Wave Encoder with lookback-buffer
1515
- Porcupine Wake-Word detector (including: "Computer", "Jarvis", "Hey SEPIA" and more)
16-
- [SEPIA STT Server](https://github.com/SEPIA-Framework/sepia-stt-server) WebSocket module for speech recognition
16+
- [SEPIA STT Server](https://github.com/SEPIA-Framework/sepia-stt-server) WebSocket module for speech recognition (see STT Server for demo)
1717
- more to come ...
1818

19-
## Tutorial
19+
## Quick-Start - Voice Recorder
2020

21-
Full tutorial code can be found at: [tutorial-code-page.html](tutorial-code-page.html).
22-
Please check out the modules and voice-recorder demo and test pages for more examples.
21+
Efficiently resampling audio to 16000 Hz and creating 16Bit mono samples for speech recognition was one of the primary objectives when building this library.
22+
While you can put together your own audio pipeline to do that (see below) there is a very convenient plugin available that does the job for you.
23+
In this quick-start guide you will learn the basics to use the 'SepiaVoiceRecorder'.
24+
25+
The first step is to import the required files and set the correct path to the modules folder. You will find more details about this step in the tutorial below. In this example the required files in 'modules' are 'speex-resample-switch.js', 'wave-encoder-worker.js' and 'shared/ring-buffer.min.js':
26+
```html
27+
<script type="text/javascript" src="test/sepia-web-audio.min.js"></script>
28+
<script type="text/javascript" src="test/sepia-recorder.min.js"></script>
29+
<script>
30+
//set correct modules folder
31+
SepiaFW.webAudio.defaultProcessorOptions.moduleFolder = "test/modules";
32+
</script>
33+
```
34+
35+
Note that we chose to copy the minified core library, the recorder plugin and the modules folder to a folder named 'test'.
36+
Now we can create our recorder:
37+
```javascript
38+
//catch some core events:
39+
SepiaVoiceRecorder.onProcessorReady = console.log; //add your own handler here
40+
SepiaVoiceRecorder.onProcessorInitError = console.error;
41+
42+
//events to process data:
43+
SepiaVoiceRecorder.onResamplerData = function(data){
44+
//here you can process raw data, e.g.:
45+
//RMS volume: data.rms
46+
//Raw 16Bit mono buffer: data.samples[0]
47+
}
48+
SepiaVoiceRecorder.onWaveEncoderAudioData = function(waveData){
49+
//when we get encoded WAV data we can add it as audio element to our page:
50+
SepiaVoiceRecorder.addAudioElementToPage(document.body, waveData, "audio/wav");
51+
}
52+
53+
//create the recorder:
54+
SepiaVoiceRecorder.create({
55+
targetSampleRate: 16000, //16kHz is actually the voice recorder default
56+
gain: 3.0, //we can pre-amplify the signal using the gain option
57+
recordingLimitMs: 30000, //Total recording limit ms
58+
});
59+
```
60+
61+
Everything is prepared. To finally start recording you should wait for the ready event and then call:
62+
```javascript
63+
//to start:
64+
SepiaVoiceRecorder.start();
65+
66+
//to stop:
67+
SepiaVoiceRecorder.stop();
68+
```
69+
70+
That's it :-).
71+
72+
Of cause there are many more events, options and features available ^^. Please check out the [voice-recorder-demo.html](voice-recorder-demo.html) for a more complex recorder setup including VAD etc..
73+
74+
75+
## Tutorial - Building Audio Pipelines
76+
77+
Full code for this tutorial can be found at: [tutorial-code-page.html](tutorial-code-page.html).
78+
Please check out the extensive [modules-demo.html](modules-demo.html) and the test pages for more examples.
2379

2480

2581
### Part 1: Basic setup and single buffer module
@@ -32,7 +88,7 @@ Copy `sepia-web-audio.js` to your project and import the library using the `<hea
3288
<script type="text/javascript" src="src/sepia-web-audio.js"></script>
3389
```
3490

35-
Copy the audio modules you are planning to use and set the correct folder:
91+
Copy the audio modules you are planning to use, for part 1 of the tutorial we only need 'buffer-switch.js'. When you're done set the correct path to your modules folder:
3692

3793
```html
3894
<script>
@@ -41,7 +97,7 @@ Copy the audio modules you are planning to use and set the correct folder:
4197
```
4298

4399
Note: In this example we've used a folder called `src` for the library and modules folder but you can choose whatever you like.
44-
Note2: Currently (v0.9.6) there is no Javascript modules support yet. Feel free to create a request via the issues section if you need it ;-).
100+
Note2: Currently there is no Javascript modules support yet. Feel free to create a request via the issues section if you need it ;-).
45101

46102
#### Create the audio processor
47103

@@ -103,7 +159,8 @@ If we don't want to restart later we can close the processor and clean up resour
103159
### Part 2: Resample input and record raw 16Bit PCM mono audio (WAV)
104160

105161
A very common use-case for this library is to resample microphone input and encode it as 16Bit PCM mono data (which is basically the default WAV file format).
106-
To make this happen we will replace the buffer module from earlier with a resampler and wave encoder module.
162+
To make this happen we will replace the buffer module from earlier with a resampler and wave encoder module. If you haven't done already please copy 'speex-resample-switch.js', 'wave-encoder-worker.js' and 'shared/ring-buffer.min.js' to your modules folder.
163+
107164
NOTE: Some browsers are actually able to natively resampling for us ^^. The resampler module will simply skip transformation in this case but it might be preferable to prevent native resampling to retain full control over the quality and speed.
108165
`SepiaFW.webAudio.isNativeStreamResamplingSupported` will be 'true' when the lib is imported because we can't test for the feature but set to 'false' after the first failed attempt of native resampling!
109166

0 commit comments

Comments
 (0)