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

How do I get the speaker's name from SpeechSynthesizer events? #819

Open
sanonz opened this issue Apr 29, 2024 · 0 comments
Open

How do I get the speaker's name from SpeechSynthesizer events? #819

sanonz opened this issue Apr 29, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@sanonz
Copy link

sanonz commented Apr 29, 2024

What happened?

Codes:

const sdk = require("microsoft-cognitiveservices-speech-sdk");

const speechConfig = sdk.SpeechConfig.fromSubscription("YourSubscriptionKey", "YourServiceRegion");
speechConfig.enableAudioLogging();

var audioFile = "YourAudioFile.wav";
const audioConfig = sdk.AudioConfig.fromAudioFileOutput(audioFile);

const synthesizer = new sdk.SpeechSynthesizer(speechConfig, audioConfig);

const ssml = `
<speak version='1.0' xml:lang='en-US' xmlns='http://www.w3.org/2001/10/synthesis' xmlns:mstts='http://www.w3.org/2001/mstts'> 
    <voice name='en-US-AvaMultilingualNeural'>
        The rainbow has seven colors
    </voice>
    <voice name='en-US-JennyNeural'>
        What's the weather like?
    </voice>
</speak>
`;

synthesizer.wordBoundary = (s, e) => {
    // Word, Punctuation, or Sentence
    var str = `WordBoundary event: \
        \r\n\tBoundaryType: ${e.boundaryType} \
        \r\n\tAudioOffset: ${(e.audioOffset + 5000) / 10000}ms \
        \r\n\tDuration: ${e.duration} \
        \r\n\tText: \"${e.text}\" \
        \r\n\tTextOffset: ${e.textOffset} \
        \r\n\tWordLength: ${e.wordLength}`;
    console.log(str);
};

synthesizer.speakSsmlAsync(ssml,
    result => {
        if (result.reason === sdk.ResultReason.SynthesizingAudioCompleted) {
            console.log("Speech synthesis succeeded.");
        } else {
            console.error("Speech synthesis failed:", result.errorDetails);
        }
        synthesizer.close();
    },
    error => {
        console.error("Speech synthesis error:", error);
    }
);

Results:

WordBoundary event:             
	BoundaryType: SentenceBoundary             
	AudioOffset: 50.5ms             
	Duration: 23750000             
	Text: "The rainbow has seven colors"             
	TextOffset: 192             
	WordLength: 28

WordBoundary event:             
	BoundaryType: SentenceBoundary             
	AudioOffset: 2475.5ms             
	Duration: 19750000             
	Text: "What's the weather like?"             
	TextOffset: 291             
	WordLength: 24

How do I get the speaker names of en-US-AvaMultilingualNeural and en-US-JennyNeural from event wordBoundary?
Such as:

synthesizer.wordBoundary = (s, e) => {
    console.log('Speaker Name:', e.speakerName);
};

Or add a new event:

synthesizer.tagReached = (s, e) => {
    console.log('Tag Name:', e.tag); // voice
    console.log('Speaker Name:', e.speakerName); // en-US-AvaMultilingualNeural or en-US
};

Version

1.36.0 (Latest)

What browser/platform are you seeing the problem on?

No response

Relevant log output

No response

@sanonz sanonz added the bug Something isn't working label Apr 29, 2024
@glharper glharper assigned yulin-li and unassigned glharper Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants