Skip to content

Commit

Permalink
refactor: Update audio file handling in SpeechToText component
Browse files Browse the repository at this point in the history
- Removed the dependency on 'form-data' and replaced it with a Blob for audio file uploads.
- Simplified the audio file appending process to the form data.
- Cleaned up the headers in the Axios request by removing unnecessary form data headers.

This change enhances the efficiency of audio file processing in the speech-to-text functionality.
  • Loading branch information
ghondar committed Dec 18, 2024
1 parent e557e88 commit cb0b81e
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions packages/components/src/speechToText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { type ClientOptions, OpenAIClient, toFile } from '@langchain/openai'
import { AssemblyAI } from 'assemblyai'
import { getFileFromStorage } from './storageUtils'
import axios from 'axios'
import FormData from 'form-data'
import Groq from 'groq-sdk'

const SpeechToTextType = {
Expand Down Expand Up @@ -81,10 +80,8 @@ export const convertSpeechToText = async (upload: IFileUpload, speechToTextConfi
const apiVersion = credentialData.apiVersion || '2024-05-15-preview'

const formData = new FormData()
formData.append('audio', audio_file, {
filename: upload.name,
contentType: upload.type
})
const audioBlob = new Blob([audio_file], { type: upload.type })
formData.append('audio', audioBlob, upload.name)

const channelsStr = speechToTextConfig.channels || '0,1'
const channels = channelsStr.split(',').map(Number)
Expand All @@ -99,8 +96,7 @@ export const convertSpeechToText = async (upload: IFileUpload, speechToTextConfi
const response = await axios.post(`${baseUrl}?api-version=${apiVersion}`, formData, {
headers: {
'Ocp-Apim-Subscription-Key': credentialData.azureSubscriptionKey,
Accept: 'application/json',
...formData.getHeaders()
Accept: 'application/json'
}
})

Expand Down

0 comments on commit cb0b81e

Please sign in to comment.