seamless-streaming / streaming-react-app /src /getTranslationSentencesFromReceivedData.ts
Anna Sun
Initial OSS demo commit
2bd3674
raw
history blame
634 Bytes
import {ServerTextData, TranslationSentences} from './types/StreamingTypes';
export default function getTranslationSentencesFromReceivedData(
receivedData: Array<ServerTextData>,
): TranslationSentences {
return receivedData
.reduce(
(acc, data) => {
// TODO: Add special handling if the payload starts/ends with an apostrophe?
const newAcc = [
...acc.slice(0, -1),
acc[acc.length - 1].trim() + ' ' + data.payload,
];
if (data.eos) {
newAcc.push('');
}
return newAcc;
},
[''],
)
.filter((s) => s.trim().length !== 0);
}