Skip to content

Commit

Permalink
Merge pull request #179 from iceljc/features/refine-chat-window
Browse files Browse the repository at this point in the history
Features/refine chat window
  • Loading branch information
iceljc authored Aug 2, 2024
2 parents dcd00e3 + 1634550 commit 915d3e6
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/lib/common/MessageImageGallery.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
artist: '',
url: isExternalUrl(item.file_url) ? item.file_url : `${PUBLIC_SERVICE_URL}${item.file_url}?access_token=${$userStore?.token}`
};
});;
});
});
}
});
Expand Down
20 changes: 11 additions & 9 deletions src/lib/common/audio-player/AudioSpeaker.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@
let speech;
onMount(() => {
const utterThis = new SpeechSynthesisUtterance();
utterThis.pitch = 1;
utterThis.rate = 1;
utterThis.onend = (e) => { stop(); };
speech = {
synth: window?.speechSynthesis,
utterThis: new SpeechSynthesisUtterance(),
utterThis: utterThis,
stop: () => stop()
};
initSpeech(speech);
Expand Down Expand Up @@ -65,15 +70,12 @@
<div
class="{disableDefaultStyles ? '' : 'chat-speaker-container'} {containerClasses}"
style={`${containerStyles}`}
on:click={() => speak()}
>
{#if !speaking}
<span>
<span on:click={() => speak()}>
{#if !speaking}
<i class="bx bx-volume" />
</span>
{:else}
<span>
{:else}
<i class="bx bx-volume-full" />
</span>
{/if}
{/if}
</span>
</div>
8 changes: 2 additions & 6 deletions src/lib/common/audio-player/store.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { derived, writable } from "svelte/store";
import { secondToTime } from "./utils";
import { speechVoices } from "$lib/services/web-speech";
import { SPEECH_VOICES } from "$lib/services/web-speech";

/** @type {HTMLAudioElement[]} */
export const instances = [];
Expand All @@ -19,14 +19,10 @@ export function initPlayer(player, dispatch) {

/** @param {import('$types').SpeechModel} speech */
export function initSpeech(speech) {
const foundVoice = speech.synth.getVoices().find(x => speechVoices.includes(x.name));
const foundVoice = speech.synth.getVoices().find(x => SPEECH_VOICES.includes(x.name));
if (foundVoice) {
speech.utterThis.voice = foundVoice;
}

speech.utterThis.pitch = 1;
speech.utterThis.rate = 1;
speech.synth.cancel();
speechInstances.push(speech);
}

Expand Down
1 change: 1 addition & 0 deletions src/lib/helpers/types/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@
// Speech
/**
* @typedef {Object} SpeechModel
* @property {string} [id]
* @property {SpeechSynthesis} synth
* @property {SpeechSynthesisUtterance} utterThis
* @property {() => void} stop
Expand Down
4 changes: 2 additions & 2 deletions src/lib/services/web-speech.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const utterThis = new SpeechSynthesisUtterance();
utterThis.pitch = 1;
utterThis.rate = 1;

export const speechVoices = [
export const SPEECH_VOICES = [
"Microsoft Michelle Online (Natural) - English (United States)",
"Google US English"
];
Expand Down Expand Up @@ -45,7 +45,7 @@ function setVoiceSynthesis() {
if (utterThis.voice == null) {
const voices = synth.getVoices();
for (let i = 0; i < voices.length; i++) {
if (speechVoices.includes(voices[i].name)) {
if (SPEECH_VOICES.includes(voices[i].name)) {
utterThis.voice = voices[i];
console.log(voices[i].name);
break;
Expand Down

0 comments on commit 915d3e6

Please sign in to comment.