11#include < thread>
22
33#include " SpeechToText.h"
4- #include < vector>
54
65namespace rnexecutorch ::models::speech_to_text {
76
@@ -43,7 +42,7 @@ SpeechToText::decode(std::span<int32_t> tokens,
4342}
4443
4544std::vector<char > SpeechToText::transcribe (std::span<float > waveform,
46- std::string languageOption) const {
45+ std::string languageOption) const {
4746 std::vector<Segment> segments =
4847 this ->asr ->transcribe (waveform, DecodingOptions (languageOption));
4948 std::string transcription;
@@ -62,8 +61,7 @@ std::vector<char> SpeechToText::transcribe(std::span<float> waveform,
6261 }
6362 }
6463
65- std::vector<char > charVector (transcription.begin (), transcription.end ());
66- return charVector;
64+ return {transcription.begin (), transcription.end ()};
6765}
6866
6967size_t SpeechToText::getMemoryLowerBound () const noexcept {
@@ -77,16 +75,17 @@ void SpeechToText::stream(std::shared_ptr<jsi::Function> callback,
7775 throw std::runtime_error (" Streaming is already in progress" );
7876 }
7977
80- auto nativeCallback = [this , callback](const std::vector<char > &committedVec,
81- const std::vector<char > &nonCommittedVec,
82- bool isDone) {
83- this ->callInvoker ->invokeAsync (
84- [callback, committedVec, nonCommittedVec, isDone](jsi::Runtime &rt) {
85- callback->call (rt, rnexecutorch::jsi_conversion::getJsiValue (committedVec, rt),
86- rnexecutorch::jsi_conversion::getJsiValue (nonCommittedVec, rt),
87- jsi::Value (isDone));
78+ auto nativeCallback =
79+ [this , callback](const std::vector<char > &committedVec,
80+ const std::vector<char > &nonCommittedVec, bool isDone) {
81+ this ->callInvoker ->invokeAsync ([callback, committedVec, nonCommittedVec,
82+ isDone](jsi::Runtime &rt) {
83+ callback->call (
84+ rt, rnexecutorch::jsi_conversion::getJsiValue (committedVec, rt),
85+ rnexecutorch::jsi_conversion::getJsiValue (nonCommittedVec, rt),
86+ jsi::Value (isDone));
8887 });
89- };
88+ };
9089
9190 this ->isStreaming = true ;
9291 while (this ->isStreaming ) {
@@ -98,17 +97,14 @@ void SpeechToText::stream(std::shared_ptr<jsi::Function> callback,
9897 ProcessResult res =
9998 this ->processor ->processIter (DecodingOptions (languageOption));
10099
101- std::vector<char > committedVec (res.committed .begin (), res.committed .end ());
102- std::vector<char > nonCommittedVec (res.nonCommitted .begin (), res.nonCommitted .end ());
103-
104- nativeCallback (committedVec, nonCommittedVec, false );
100+ nativeCallback ({res.committed .begin (), res.committed .end ()},
101+ {res.nonCommitted .begin (), res.nonCommitted .end ()}, false );
105102 this ->readyToProcess = false ;
106103 }
107104
108105 std::string committed = this ->processor ->finish ();
109- std::vector<char > committedVec (committed.begin (), committed.end ());
110106
111- nativeCallback (committedVec , {}, true );
107+ nativeCallback ({committed. begin (), committed. end ()} , {}, true );
112108
113109 this ->resetStreamState ();
114110}
0 commit comments