refac: voice call

This commit is contained in:
Timothy J. Baek
2024-06-13 20:15:23 -07:00
parent 7ea572fdca
commit 7f70de99d3
3 changed files with 407 additions and 358 deletions
+18
View File
@@ -443,6 +443,24 @@ export const extractSentences = (text) => {
.filter((sentence) => sentence !== '');
};
export const extractSentencesForAudio = (text) => {
return extractSentences(text).reduce((mergedTexts, currentText) => {
const lastIndex = mergedTexts.length - 1;
if (lastIndex >= 0) {
const previousText = mergedTexts[lastIndex];
const wordCount = previousText.split(/\s+/).length;
if (wordCount < 2) {
mergedTexts[lastIndex] = previousText + ' ' + currentText;
} else {
mergedTexts.push(currentText);
}
} else {
mergedTexts.push(currentText);
}
return mergedTexts;
}, []);
};
export const blobToFile = (blob, fileName) => {
// Create a new File object from the Blob
const file = new File([blob], fileName, { type: blob.type });