Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Locale support for TTS #10

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "speechstate",
"version": "2.5.0",
"version": "2.6.0",
"license": "GPL-3.0",
"homepage": "http://localhost/speechstate",
"main": "./dist/index.js",
Expand Down
9 changes: 5 additions & 4 deletions src/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import {
Settings,
} from "./types";
import { createBrowserInspector } from "@statelyai/inspect";
import { AZURE_KEY } from "./credentials";

const inspector = createBrowserInspector();

const azureSpeechCredentials: AzureSpeechCredentials = {
endpoint:
"https://northeurope.api.cognitive.microsoft.com/sts/v1.0/issuetoken",
key: "",
"https://swedencentral.api.cognitive.microsoft.com/sts/v1.0/issuetoken",
key: AZURE_KEY,
};

const azureLanguageCredentials: AzureLanguageCredentials = {
Expand All @@ -26,11 +27,11 @@ const azureLanguageCredentials: AzureLanguageCredentials = {

const settings: Settings = {
azureCredentials: azureSpeechCredentials,
azureRegion: "northeurope",
azureRegion: "swedencentral",
azureLanguageCredentials: azureLanguageCredentials,
asrDefaultCompleteTimeout: 0,
asrDefaultNoInputTimeout: 5000,
locale: "en-US",
locale: "sv-SE",
ttsDefaultVoice: "en-US-DavisNeural",
// speechRecognitionEndpointId: "",
};
Expand Down
1 change: 1 addition & 0 deletions src/speechstate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const speechstate = setup({
audioContext: context.audioContext,
azureCredentials: context.settings.azureCredentials,
azureRegion: context.settings.azureRegion,
locale: context.settings.locale,
},
});
},
Expand Down
10 changes: 8 additions & 2 deletions src/tts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export const ttsMachine = setup({
const content = wrapSSML(
(input as any).utterance,
(input as any).voice,
(input as any).locale,
(input as any).ttsLexicon,
1,
); // todo speech rate;
Expand Down Expand Up @@ -163,6 +164,7 @@ export const ttsMachine = setup({
audioContext: input.audioContext,
azureCredentials: input.azureCredentials,
azureRegion: input.azureRegion,
locale: input.locale || "en-US",
buffer: "",
}),
initial: "GetToken",
Expand Down Expand Up @@ -397,6 +399,7 @@ export const ttsMachine = setup({
context.currentVoice ||
context.agenda.voice ||
context.ttsDefaultVoice,
locale: context.locale,
utterance: context.utteranceFromStream,
}),
},
Expand Down Expand Up @@ -441,6 +444,7 @@ export const ttsMachine = setup({
ttsLexicon: context.ttsLexicon,
voice: context.agenda.voice || context.ttsDefaultVoice,
// streamURL: context.agenda.streamURL,
locale: context.locale,
utterance: context.agenda.utterance,
}),
},
Expand Down Expand Up @@ -500,16 +504,18 @@ export const ttsMachine = setup({
const wrapSSML = (
text: string,
voice: string,
locale: string,
lexicon: string,
speechRate: number,
): string => {
let content = `<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xmlns:mstts="http://www.w3.org/2001/mstts" xml:lang="en-US"><voice name="${voice}">`;
let content = `<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xmlns:mstts="http://www.w3.org/2001/mstts" xml:lang="en-US"><voice name="${voice}"><lang xml:lang="${locale}">`;
if (lexicon) {
content = content + `<lexicon uri="${lexicon}"/>`;
}
content =
content +
`<prosody rate="${speechRate}">` +
`${text}</prosody></voice></speak>`;
`${text}</prosody></lang></voice></speak>`;
console.debug(content);
return content;
};
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export interface TTSInit {
azureRegion: string;
ttsDefaultVoice: string;
ttsLexicon?: string;
locale: string;
}

export interface TTSContext extends TTSInit {
Expand Down