File size: 549 Bytes
2485dd8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
import {ServerTextData, TranslationSentences} from './types/StreamingTypes';
export default function getTranslationSentencesFromReceivedData(
receivedData: Array<ServerTextData>,
): TranslationSentences {
return receivedData
.reduce(
(acc, data) => {
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);
}
|