Skip to content

Commit

Permalink
Merge branch 'master' into infinite-listen
Browse files Browse the repository at this point in the history
  • Loading branch information
sasha-tlt authored Jul 23, 2024
2 parents d4e7aa8 + 8def815 commit 913b423
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 36 deletions.
51 changes: 51 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,54 @@
# v1.35.0 (Wed Jun 05 2024)

#### 🚀 Enhancement

- feat: Обновлён Scenario [#214](https://github.com/salute-developers/salutejs-client/pull/214) ([@evgeniysemin](https://github.com/evgeniysemin))

#### ⚠️ Pushed to `master`

- test: [autocommit] Save current bundle report ([@Salute-Eva](https://github.com/Salute-Eva))

#### Authors: 2

- [@evgeniysemin](https://github.com/evgeniysemin)
- [@Salute-Eva](https://github.com/Salute-Eva)

---

# v1.34.1 (Sat Apr 27 2024)

#### 🐛 Bug Fix

- fix: window navigator on server [#213](https://github.com/salute-developers/salutejs-client/pull/213) ([@soulko](https://github.com/soulko))

#### ⚠️ Pushed to `master`

- test: [autocommit] Save current bundle report ([@Salute-Eva](https://github.com/Salute-Eva))

#### Authors: 2

- [@Salute-Eva](https://github.com/Salute-Eva)
- Anton Kostenko ([@soulko](https://github.com/soulko))

---

# v1.34.0 (Thu Apr 25 2024)

#### 🚀 Enhancement

- feat: Добавлено событие с данными аналайзера [#212](https://github.com/salute-developers/salutejs-client/pull/212) ([@evgeniysemin](https://github.com/evgeniysemin))

#### ⚠️ Pushed to `master`

- test: [autocommit] Save current bundle report ([@Salute-Eva](https://github.com/Salute-Eva))

#### Authors: 2

- [@evgeniysemin](https://github.com/evgeniysemin)
- [@Salute-Eva](https://github.com/Salute-Eva)

---

# v1.33.6 (Tue Apr 16 2024)

#### 🐛 Bug Fix
Expand Down
2 changes: 1 addition & 1 deletion bundle-report.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"{\"dist/assistant-hash1.js\":435929,\"dist/createAssistantDevOrigin.js\":122055,\"dist/index.js\":69234,\"esm/assistant-hash1.js\":141701,\"esm/assistant.js\":123,\"esm/common-hash1.js\":6287,\"esm/createAssistant.js\":24980,\"esm/createAssistantDev.js\":374,\"esm/createAssistantDevOrigin.js\":121929,\"esm/index.js\":1017,\"esm/mock.js\":5420,\"esm/record-hash1.js\":63740,\"esm/sdk-hash1.js\":261834,\"umd/assistant.development.min.js\":215522,\"umd/assistant.production.min.js\":12890}"
"{\"dist/assistant-hash1.js\":436556,\"dist/createAssistantDevOrigin.js\":122055,\"dist/index.js\":69234,\"esm/assistant-hash1.js\":142308,\"esm/assistant.js\":123,\"esm/common-hash1.js\":6287,\"esm/createAssistant.js\":24980,\"esm/createAssistantDev.js\":374,\"esm/createAssistantDevOrigin.js\":121929,\"esm/index.js\":1017,\"esm/mock.js\":5420,\"esm/record-hash1.js\":63740,\"esm/sdk-hash1.js\":261834,\"umd/assistant.development.min.js\":215764,\"umd/assistant.production.min.js\":12890}"
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@salutejs/client",
"version": "1.33.6",
"version": "1.35.0",
"description": "Модуль взаимодействия с виртуальным ассистентом",
"author": "Salute Frontend Team <[email protected]>",
"main": "dist/index.js",
Expand Down Expand Up @@ -34,7 +34,7 @@
"smartapp"
],
"dependencies": {
"@salutejs/scenario": "^0.38.0",
"@salutejs/scenario": "1.2.0",
"lodash.clonedeep": "^4.5.0",
"long": "^5.2.3",
"protobufjs": "^7.2.6",
Expand Down
4 changes: 4 additions & 0 deletions src/assistantSdk/assistant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export type AssistantEvent = {
emotion?: EmotionId;
mtt?: { response: Music2TrackProtocol.MttResponse; mid: OriginalMessageType['messageId'] };
listener?: { status: VoiceListenerStatus };
voiceAnalyser?: { data: Uint8Array };
};

export type VpsEvent =
Expand Down Expand Up @@ -137,6 +138,7 @@ export interface CreateAssistantDevOptions {
getInitialMeta?: () => Promise<Record<string, unknown>>;
/** Подставляет мету в первый чанк с голосом для управления рекогнайзером */
getVoiceMeta?: () => Record<string, unknown>;
useVoiceAnalyser?: boolean;
}

type BackgroundAppOnCommand<T> = (
Expand All @@ -162,6 +164,7 @@ export const createAssistant = ({
getInitialMeta,
getVoiceMeta,
checkCertUrl,
useVoiceAnalyser,
...configuration
}: AssistantParams) => {
const { on, emit } = createNanoEvents<AssistantEvents>();
Expand Down Expand Up @@ -301,6 +304,7 @@ export const createAssistant = ({
protocol.changeSettings({ dubbing: 1 });
}
},
useVoiceAnalyser,
);

/** завершает текущий апп */
Expand Down
10 changes: 7 additions & 3 deletions src/assistantSdk/voice/listener/navigatorAudioProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ let source: MediaStreamAudioSourceNode;
*/
const createAudioRecorder = (
stream: MediaStream,
cb: (buffer: ArrayBuffer, last: boolean) => void,
cb: (buffer: ArrayBuffer, analyserArray: Uint8Array | null, last: boolean) => void,
useAnalyser?: boolean,
): Promise<() => void> =>
new Promise((resolve) => {
let state: 'inactive' | 'recording' = 'inactive';
Expand Down Expand Up @@ -82,13 +83,16 @@ const createAudioRecorder = (
* @param cb Callback, куда будут передаваться чанки с голосом пользователя
* @returns Promise, который содержит функцию прерывающую слушание
*/
export const createNavigatorAudioProvider = (cb: (buffer: ArrayBuffer, last: boolean) => void): Promise<() => void> =>
export const createNavigatorAudioProvider = (
cb: (buffer: ArrayBuffer, analyserArray: Uint8Array | null, last: boolean) => void,
useAnalyser?: boolean,
): Promise<() => void> =>
navigator.mediaDevices
.getUserMedia({
audio: true,
})
.then((stream) => {
return createAudioRecorder(stream, cb);
return createAudioRecorder(stream, cb, useAnalyser);
})
.catch((err) => {
if (window.location.protocol === 'http:') {
Expand Down
10 changes: 3 additions & 7 deletions src/assistantSdk/voice/listener/voiceListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { createNavigatorAudioProvider } from './navigatorAudioProvider';

export type VoiceListenerStatus = 'listen' | 'started' | 'stopped';

export type VoiceHandler = (data: Uint8Array, last: boolean) => void;
export type VoiceHandler = (data: Uint8Array, analyserArray: Uint8Array | null, last: boolean) => void;

type VoiceStreamEvents = {
status: (status: VoiceListenerStatus) => void;
Expand All @@ -16,11 +16,7 @@ type VoiceStreamEvents = {
* @param createAudioProvider Источник голоса
* @returns Api для запуска и остановки слушания
*/
export const createVoiceListener = (
createAudioProvider: (
cb: (data: ArrayBuffer, last: boolean) => void,
) => Promise<() => void> = createNavigatorAudioProvider,
) => {
export const createVoiceListener = (createAudioProvider = createNavigatorAudioProvider) => {
const { emit, on } = createNanoEvents<VoiceStreamEvents>();
let stopRecord: () => void;
let status: VoiceListenerStatus = 'stopped';
Expand All @@ -40,7 +36,7 @@ export const createVoiceListener = (
status = 'started';
emit('status', 'started');

return createAudioProvider((data: ArrayBuffer, last: boolean) => handleVoice(new Uint8Array(data), last))
return createAudioProvider((data, analyser, last) => handleVoice(new Uint8Array(data), analyser, last))
.then((recStop) => {
stopRecord = recStop;
})
Expand Down
9 changes: 5 additions & 4 deletions src/assistantSdk/voice/player/iosSilentModePatch.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const ctx = typeof window !== 'undefined' ? window : self;
const IS_APPLE_MOBILE =
(/iPad|iPhone|iPod/.test(navigator.platform) ||
(navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1)) &&
!(ctx as any).MSStream;
typeof window !== 'undefined'
? (/iPad|iPhone|iPod/.test(navigator.platform) ||
(navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1)) &&
!(window as any).MSStream
: false;

function createSilentAudioFile(sampleRate: number) {
const arrayBuffer = new ArrayBuffer(10);
Expand Down
13 changes: 10 additions & 3 deletions src/assistantSdk/voice/voice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { AppInfo, EmotionId, OriginalMessageType, Mid, SystemMessageDataType, Me
import { AssistantSettings } from '../assistant';
import { MutexedObject } from '../mutexedObject';

import { createNavigatorAudioProvider } from './listener/navigatorAudioProvider';
import { createVoiceListener, VoiceListenerStatus } from './listener/voiceListener';
import { createVoicePlayer } from './player/voicePlayer';
import { resolveAudioContext, isAudioSupported } from './audioContext';
Expand Down Expand Up @@ -36,13 +37,15 @@ export const createVoice = (
listener?: { status: VoiceListenerStatus };
mtt?: { response: Music2TrackProtocol.MttResponse; mid: OriginalMessageType['messageId'] };
tts?: TtsEvent;
voiceAnalyser?: { data: Uint8Array };
}) => void,
/// пока onReady не вызван, треки не воспроизводятся
/// когда случится onReady, очередь треков начнет проигрываться
onReady?: () => void,
useAnalyser?: boolean,
) => {
let voicePlayer: ReturnType<typeof createVoicePlayer>;
const listener = createVoiceListener();
const listener = createVoiceListener((cb) => createNavigatorAudioProvider(cb, useAnalyser));
const subscriptions: Array<() => void> = [];
const appInfoDict: Record<string, AppInfo> = {};
const mesIdQueue: Array<string> = [];
Expand Down Expand Up @@ -128,8 +131,12 @@ export const createVoice = (

currentVoiceMessageId = messageId;

return listener.listen((...args) => {
sendVoice(...args, messageName);
return listener.listen((chunk, analyser, last) => {
if (analyser) {
emit({ voiceAnalyser: { data: analyser } });
}

sendVoice(chunk, last, messageName);
});
},
{
Expand Down
9 changes: 2 additions & 7 deletions src/typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
UUID,
Meta as ScenarioMeta,
SystemMessagePayload,
VpsMessageReasonModel,
} from '@salutejs/scenario';

import {
Expand Down Expand Up @@ -465,14 +466,8 @@ export interface AssistantBackgroundAppInfo {
state: Record<string, unknown>;
}

export interface SourceMeta {
sourceType?: string;
sourceName?: string;
suggestTitle?: string;
}
export interface Meta extends ScenarioMeta, AssistantMeta {
background_apps: AssistantBackgroundAppInfo[];
source?: SourceMeta;
source?: VpsMessageReasonModel;
[key: string]: unknown;
}

Expand Down

0 comments on commit 913b423

Please sign in to comment.