Skip to content

Commit 9712cd1

Browse files
author
Mateusz Kopciński
committed
review fix
1 parent dad4a9d commit 9712cd1

File tree

2 files changed

+26
-28
lines changed

2 files changed

+26
-28
lines changed

packages/react-native-executorch/common/rnexecutorch/host_objects/JsiConversions.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ inline JSTensorViewIn getValue<JSTensorViewIn>(const jsi::Value &val,
6666
tensorView.sizes.reserve(numShapeDims);
6767

6868
for (size_t i = 0; i < numShapeDims; ++i) {
69-
int32_t dim = getValue<int32_t>(shapeArray.getValueAtIndex(runtime, i), runtime);
69+
int32_t dim =
70+
getValue<int32_t>(shapeArray.getValueAtIndex(runtime, i), runtime);
7071
tensorView.sizes.push_back(dim);
7172
}
7273

@@ -173,23 +174,24 @@ inline std::vector<T> getArrayAsVector(const jsi::Value &val,
173174
return result;
174175
}
175176

176-
177177
// Template specializations for std::vector<T> types
178178
template <>
179-
inline std::vector<JSTensorViewIn> getValue<std::vector<JSTensorViewIn>>(const jsi::Value &val,
180-
jsi::Runtime &runtime) {
179+
inline std::vector<JSTensorViewIn>
180+
getValue<std::vector<JSTensorViewIn>>(const jsi::Value &val,
181+
jsi::Runtime &runtime) {
181182
return getArrayAsVector<JSTensorViewIn>(val, runtime);
182183
}
183184

184185
template <>
185-
inline std::vector<std::string> getValue<std::vector<std::string>>(const jsi::Value &val,
186-
jsi::Runtime &runtime) {
186+
inline std::vector<std::string>
187+
getValue<std::vector<std::string>>(const jsi::Value &val,
188+
jsi::Runtime &runtime) {
187189
return getArrayAsVector<std::string>(val, runtime);
188190
}
189191

190192
template <>
191-
inline std::vector<int32_t> getValue<std::vector<int32_t>>(const jsi::Value &val,
192-
jsi::Runtime &runtime) {
193+
inline std::vector<int32_t>
194+
getValue<std::vector<int32_t>>(const jsi::Value &val, jsi::Runtime &runtime) {
193195
return getArrayAsVector<int32_t>(val, runtime);
194196
}
195197

@@ -284,7 +286,7 @@ inline jsi::Value getJsiValue(const std::vector<char> &vec,
284286
jsi::Runtime &runtime) {
285287
jsi::Array array(runtime, vec.size());
286288
for (size_t i = 0; i < vec.size(); i++) {
287-
array.setValueAtIndex(runtime, i, jsi::Value(static_cast<char>(vec[i])));
289+
array.setValueAtIndex(runtime, i, jsi::Value(vec[i]));
288290
}
289291
return {runtime, array};
290292
}

packages/react-native-executorch/common/rnexecutorch/models/speech_to_text/SpeechToText.cpp

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include <thread>
22

33
#include "SpeechToText.h"
4-
#include <vector>
54

65
namespace rnexecutorch::models::speech_to_text {
76

@@ -43,7 +42,7 @@ SpeechToText::decode(std::span<int32_t> tokens,
4342
}
4443

4544
std::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

6967
size_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

Comments
 (0)