@@ -36,8 +36,8 @@ SpeechToText::decode(std::span<int32_t> tokens,
3636 return this ->makeOwningBuffer (decoderOutput);
3737}
3838
39- std::string SpeechToText::transcribe (std::span<float > waveform,
40- std::string languageOption) const {
39+ std::vector< char > SpeechToText::transcribe (std::span<float > waveform,
40+ std::string languageOption) const {
4141 std::vector<Segment> segments =
4242 this ->asr ->transcribe (waveform, DecodingOptions (languageOption));
4343 std::string transcription;
@@ -55,7 +55,8 @@ std::string SpeechToText::transcribe(std::span<float> waveform,
5555 transcription += word.content ;
5656 }
5757 }
58- return transcription;
58+
59+ return {transcription.begin (), transcription.end ()};
5960}
6061
6162size_t SpeechToText::getMemoryLowerBound () const noexcept {
@@ -79,16 +80,17 @@ void SpeechToText::stream(std::shared_ptr<jsi::Function> callback,
7980 throw std::runtime_error (" Streaming is already in progress" );
8081 }
8182
82- auto nativeCallback = [this , callback](const std::string &committed,
83- const std::string &nonCommitted,
84- bool isDone) {
85- this ->callInvoker ->invokeAsync (
86- [callback, committed, nonCommitted, isDone](jsi::Runtime &rt) {
87- callback->call (rt, jsi::String::createFromUtf8 (rt, committed),
88- jsi::String::createFromUtf8 (rt, nonCommitted),
89- jsi::Value (isDone));
83+ auto nativeCallback =
84+ [this , callback](const std::vector<char > &committedVec,
85+ const std::vector<char > &nonCommittedVec, bool isDone) {
86+ this ->callInvoker ->invokeAsync ([callback, committedVec, nonCommittedVec,
87+ isDone](jsi::Runtime &rt) {
88+ callback->call (
89+ rt, rnexecutorch::jsi_conversion::getJsiValue (committedVec, rt),
90+ rnexecutorch::jsi_conversion::getJsiValue (nonCommittedVec, rt),
91+ jsi::Value (isDone));
9092 });
91- };
93+ };
9294
9395 this ->isStreaming = true ;
9496 while (this ->isStreaming ) {
@@ -99,12 +101,15 @@ void SpeechToText::stream(std::shared_ptr<jsi::Function> callback,
99101 }
100102 ProcessResult res =
101103 this ->processor ->processIter (DecodingOptions (languageOption));
102- nativeCallback (res.committed , res.nonCommitted , false );
104+
105+ nativeCallback ({res.committed .begin (), res.committed .end ()},
106+ {res.nonCommitted .begin (), res.nonCommitted .end ()}, false );
103107 this ->readyToProcess = false ;
104108 }
105109
106110 std::string committed = this ->processor ->finish ();
107- nativeCallback (committed, " " , true );
111+
112+ nativeCallback ({committed.begin (), committed.end ()}, {}, true );
108113
109114 this ->resetStreamState ();
110115}
0 commit comments