@nualang/nualang-ui-components 0.1.1210 → 0.1.1211
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hooks/useRecognition.js +2 -11
- package/dist/utils/index.js +1 -6
- package/package.json +1 -1
|
@@ -154,22 +154,12 @@ function useRecognition(props = {}) {
|
|
|
154
154
|
*/
|
|
155
155
|
const initRecording = async (gcloudParams, onData, onError) => {
|
|
156
156
|
try {
|
|
157
|
-
const {
|
|
158
|
-
mediaDevices
|
|
159
|
-
} = navigator;
|
|
160
|
-
const [availableMicrophones, activeMicrophone, sampleRate] = await (0, _index.getMicrophoneInfo)(mediaDevices);
|
|
161
157
|
await setupAudioContext();
|
|
162
|
-
let sampleRateToUse = sampleRate;
|
|
163
|
-
if (sampleRate && sampleRate < 8000) {
|
|
164
|
-
sampleRateToUse = 8000;
|
|
165
|
-
} else if (sampleRate && sampleRate > 48000) {
|
|
166
|
-
sampleRateToUse = 48000;
|
|
167
|
-
}
|
|
168
158
|
const handleSuccess = function (stream) {
|
|
169
159
|
const gcloudConfig = {
|
|
170
160
|
config: {
|
|
171
161
|
encoding: "LINEAR16",
|
|
172
|
-
sampleRateHertz:
|
|
162
|
+
sampleRateHertz: 16000,
|
|
173
163
|
languageCode: gcloudParams.languageCode || "en-US",
|
|
174
164
|
profanityFilter: true,
|
|
175
165
|
enableWordTimeOffsets: false,
|
|
@@ -182,6 +172,7 @@ function useRecognition(props = {}) {
|
|
|
182
172
|
interimResults: gcloudParams.interimResults // If you want interim results, set this to true
|
|
183
173
|
};
|
|
184
174
|
socket.emit("startGoogleCloudStream", gcloudConfig, version); // init socket Google Speech Connection
|
|
175
|
+
|
|
185
176
|
streamRef.current = stream;
|
|
186
177
|
audioInputRef.current = audioContextRef.current.createMediaStreamSource(stream);
|
|
187
178
|
serverErrorRef.current = null;
|
package/dist/utils/index.js
CHANGED
|
@@ -454,12 +454,7 @@ const getMicrophoneInfo = async mediaDevices => {
|
|
|
454
454
|
const availableMicrophoneNames = microphones?.filter(device => device.deviceId !== "default").map(device => device.label).join(", ") || "No available microphones detected";
|
|
455
455
|
const activeMicrophone = microphones?.length > 0 ? microphones.find(mic => mic.deviceId === "default") || microphones[0] : null;
|
|
456
456
|
const activeMicrophoneName = activeMicrophone?.label.split("Default - ").pop() || "No active microphone detected";
|
|
457
|
-
|
|
458
|
-
// Create an AudioContext with the stream from the active microphone
|
|
459
|
-
|
|
460
|
-
const capabilities = activeMicrophone.getCapabilities();
|
|
461
|
-
let sampleRate = capabilities?.sampleRate.max || capabilities?.sampleRate.exacty;
|
|
462
|
-
return [availableMicrophoneNames, activeMicrophoneName, sampleRate];
|
|
457
|
+
return [availableMicrophoneNames, activeMicrophoneName];
|
|
463
458
|
} catch (error) {
|
|
464
459
|
console.error("Error accessing the microphone:", error);
|
|
465
460
|
}
|