Skip to content

Commit 558277c

Browse files
Removed exposed Speech Service API key from network calls
1 parent 400d1f8 commit 558277c

2 files changed

Lines changed: 11 additions & 12 deletions

File tree

code/create_app.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,6 @@ def speech_config():
526526
if response.status_code == 200:
527527
return {
528528
"token": response.text,
529-
"key": speech_key,
530529
"region": env_helper.AZURE_SPEECH_SERVICE_REGION,
531530
"languages": env_helper.AZURE_SPEECH_RECOGNIZER_LANGUAGES,
532531
}

code/frontend/src/components/Answer/Answer.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export const Answer = ({
5151
const [audioContext, setAudioContext] = useState<AudioContext | null>(null); //Manully manage the audio context eg pausing resuming
5252

5353
const [synthesizerData, setSynthesizerData] = useState({
54-
key: "",
54+
token: "",
5555
region: "",
5656
});
5757
const [synthesizer, setSynthesizer] =
@@ -70,8 +70,8 @@ export const Answer = ({
7070
};
7171

7272
const initializeSynthesizer = () => {
73-
const speechConfig = sdk.SpeechConfig.fromSubscription(
74-
synthesizerData.key,
73+
const speechConfig = sdk.SpeechConfig.fromAuthorizationToken(
74+
synthesizerData.token,
7575
synthesizerData.region
7676
);
7777
const newAudioDestination = new SpeechSDK.SpeakerAudioDestination();
@@ -90,7 +90,7 @@ export const Answer = ({
9090
};
9191

9292
useEffect(() => {
93-
if (synthesizerData.key != "") {
93+
if (synthesizerData.token != "") {
9494
initializeSynthesizer();
9595

9696
return () => {
@@ -112,12 +112,12 @@ export const Answer = ({
112112
const response = await fetch("/api/speech");
113113
try {
114114
if (!response.ok) {
115-
throw new Error("Network response was not ok");
115+
throw new Error("Network response was not ok");
116116
}
117-
const data = await response.json();
118-
setSynthesizerData({ key: data.key, region: data.region });
119-
} catch(e) {
120-
console.log(e)
117+
const data = await response.json();
118+
setSynthesizerData({ token: data.token, region: data.region });
119+
} catch (e) {
120+
console.log(e);
121121
}
122122
};
123123
fetchSythesizerData();
@@ -334,7 +334,7 @@ export const Answer = ({
334334
}
335335
data-testid="toggle-citations-list"
336336
>
337-
<Text className={styles.accordionTitle}>
337+
<Text className={styles.accordionTitle}>
338338
<span data-testid="no-of-references">
339339
{parsedAnswer.citations.length > 1
340340
? parsedAnswer.citations.length + " references"
@@ -375,7 +375,7 @@ export const Answer = ({
375375
onKeyDown={(e) =>
376376
e.key === " " || e.key === "Enter"
377377
? onCitationClicked(citation)
378-
: () => {}
378+
: () => { }
379379
}
380380
tabIndex={0}
381381
title={createCitationFilepath(citation, ++idx)}

0 commit comments

Comments
 (0)