Skip to content

Commit

Permalink
fix: audio should set autoPlay if you want to play audio when it's lo…
Browse files Browse the repository at this point in the history
…aded
  • Loading branch information
YanceyOfficial committed Dec 8, 2024
1 parent 720e1d3 commit 04904c0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
6 changes: 4 additions & 2 deletions src/components/ChatBox/ChatMessages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,13 @@ const ChatMessages: FC = () => {
>
<SpeakerWaveIcon
className={classNames(
'relative h-5 w-5 text-black dark:text-white'
'relative mt-3 h-5 w-5 text-black dark:text-white'
)}
/>
</button>
{audioUrl && <audio src={audioUrl} className="hidden" />}
{audioUrl && (
<audio src={audioUrl} className="hidden" autoPlay />
)}
</div>
) : (
<div>
Expand Down
16 changes: 2 additions & 14 deletions src/hooks/useSpeech.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,26 @@
import { useRecoilValue, useSetRecoilState } from 'recoil'
import { CompletionConfiguration } from 'src/configurations/completion'
import { useClients } from 'src/hooks'
import { showRequestErrorToast } from 'src/shared/utils'
import { currConversationState, loadingState } from 'src/stores/conversation'
import { settingsState } from 'src/stores/settings'
import { Companies } from 'src/types/global'

const useSpeech = () => {
const { openAiClient, azureClient, azureSpeechClient } = useClients()
const { openAiClient, azureSpeechClient } = useClients()
const currConversation = useRecoilValue(currConversationState)
const setLoading = useSetRecoilState(loadingState)
const settings = useRecoilValue(settingsState)

if (!settings || !currConversation) return

const {
model,
maxTokens,
temperature,
topP,
frequencyPenalty,
presencePenalty,
preResponse,
postResponse
} = currConversation.configuration as CompletionConfiguration

const createSpeechByOpenAI = async (text: string) => {
try {
setLoading(true)

const speech = await openAiClient.audio.speech.create({
model: 'tts-1',
input: text,
voice: 'alloy'
voice: 'nova'
})
const audioBlob = await speech.blob()
const audioUrl = URL.createObjectURL(audioBlob)
Expand Down

0 comments on commit 04904c0

Please sign in to comment.