Skip to content

Commit 188fae0

Browse files
authored
V0.5.5 (#602)
## Description Changes: - add missing `<sstream>` include - update namespace usage ### Introduces a breaking change? - [ ] Yes - [x] No ### Type of change - [x] Bug fix (change which fixes an issue) - [ ] New feature (change which adds functionality) - [ ] Documentation update (improves or adds clarity to existing documentation) - [x] Other (chores, tests, code style improvements etc.) ### Tested on - [x] iOS - [x] Android ### Checklist - [x] I have performed a self-review of my code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have updated the documentation accordingly - [x] My changes generate no new warnings
1 parent a3a0d40 commit 188fae0

9 files changed

Lines changed: 38 additions & 35 deletions

File tree

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
namespace rnexecutorch::models::speech_to_text {
66

77
using namespace ::executorch::extension;
8+
using namespace asr;
9+
using namespace types;
10+
using namespace stream;
811

912
SpeechToText::SpeechToText(const std::string &encoderSource,
1013
const std::string &decoderSource,

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ namespace rnexecutorch {
66

77
namespace models::speech_to_text {
88

9-
using namespace asr;
10-
using namespace types;
11-
using namespace stream;
12-
139
class SpeechToText {
1410
public:
1511
explicit SpeechToText(const std::string &encoderSource,
@@ -35,14 +31,14 @@ class SpeechToText {
3531
std::unique_ptr<BaseModel> encoder;
3632
std::unique_ptr<BaseModel> decoder;
3733
std::unique_ptr<TokenizerModule> tokenizer;
38-
std::unique_ptr<ASR> asr;
34+
std::unique_ptr<asr::ASR> asr;
3935

4036
std::shared_ptr<OwningArrayBuffer>
4137
makeOwningBuffer(std::span<const float> vectorView) const;
4238

4339
// Stream
4440
std::shared_ptr<react::CallInvoker> callInvoker;
45-
std::unique_ptr<OnlineASRProcessor> processor;
41+
std::unique_ptr<stream::OnlineASRProcessor> processor;
4642
bool isStreaming;
4743
bool readyToProcess;
4844

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <random>
2+
#include <sstream>
23

34
#include "ASR.h"
45
#include "executorch/extension/tensor/tensor_ptr.h"
@@ -8,6 +9,8 @@
89

910
namespace rnexecutorch::models::speech_to_text::asr {
1011

12+
using namespace types;
13+
1114
ASR::ASR(const models::BaseModel *encoder, const models::BaseModel *decoder,
1215
const TokenizerModule *tokenizer)
1316
: encoder(encoder), decoder(decoder), tokenizer(tokenizer),

packages/react-native-executorch/common/rnexecutorch/models/speech_to_text/asr/ASR.h

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@
88

99
namespace rnexecutorch::models::speech_to_text::asr {
1010

11-
using namespace types;
12-
1311
class ASR {
1412
public:
1513
explicit ASR(const models::BaseModel *encoder,
1614
const models::BaseModel *decoder,
1715
const TokenizerModule *tokenizer);
18-
std::vector<Segment> transcribe(std::span<const float> waveform,
19-
const DecodingOptions &options) const;
16+
std::vector<types::Segment>
17+
transcribe(std::span<const float> waveform,
18+
const types::DecodingOptions &options) const;
2019
std::vector<float> encode(std::span<const float> waveform) const;
2120
std::vector<float> decode(std::span<int32_t> tokens,
2221
std::span<float> encoderOutput) const;
@@ -43,16 +42,18 @@ class ASR {
4342
// Number of mel frames output by the encoder (derived from input spectrogram)
4443
constexpr static int32_t kNumFrames = 1500;
4544

46-
std::vector<int32_t> getInitialSequence(const DecodingOptions &options) const;
47-
GenerationResult generate(std::span<const float> waveform, float temperature,
48-
const DecodingOptions &options) const;
49-
std::vector<Segment>
45+
std::vector<int32_t>
46+
getInitialSequence(const types::DecodingOptions &options) const;
47+
types::GenerationResult generate(std::span<const float> waveform,
48+
float temperature,
49+
const types::DecodingOptions &options) const;
50+
std::vector<types::Segment>
5051
generateWithFallback(std::span<const float> waveform,
51-
const DecodingOptions &options) const;
52-
std::vector<Segment>
52+
const types::DecodingOptions &options) const;
53+
std::vector<types::Segment>
5354
calculateWordLevelTimestamps(std::span<const int32_t> tokens,
5455
std::span<const float> waveform) const;
55-
std::vector<Word>
56+
std::vector<types::Word>
5657
estimateWordLevelTimestampsLinear(std::span<const int32_t> tokens,
5758
int32_t start, int32_t end) const;
5859
float getCompressionRatio(const std::string &text) const;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace rnexecutorch::models::speech_to_text::stream {
44

5+
using namespace types;
6+
57
void HypothesisBuffer::insert(std::span<const Word> newWords, float offset) {
68
this->fresh.clear();
79
for (const auto &word : newWords) {

packages/react-native-executorch/common/rnexecutorch/models/speech_to_text/stream/HypothesisBuffer.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,19 @@
77

88
namespace rnexecutorch::models::speech_to_text::stream {
99

10-
using namespace types;
11-
1210
class HypothesisBuffer {
1311
public:
14-
void insert(std::span<const Word> newWords, float offset);
15-
std::deque<Word> flush();
12+
void insert(std::span<const types::Word> newWords, float offset);
13+
std::deque<types::Word> flush();
1614
void popCommitted(float time);
17-
std::deque<Word> complete() const;
15+
std::deque<types::Word> complete() const;
1816

1917
private:
2018
float lastCommittedTime = 0.0f;
2119

22-
std::deque<Word> committedInBuffer;
23-
std::deque<Word> buffer;
24-
std::deque<Word> fresh;
20+
std::deque<types::Word> committedInBuffer;
21+
std::deque<types::Word> buffer;
22+
std::deque<types::Word> fresh;
2523
};
2624

2725
} // namespace rnexecutorch::models::speech_to_text::stream

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
namespace rnexecutorch::models::speech_to_text::stream {
66

7+
using namespace asr;
8+
using namespace types;
9+
710
OnlineASRProcessor::OnlineASRProcessor(const ASR *asr) : asr(asr) {}
811

912
void OnlineASRProcessor::insertAudioChunk(std::span<const float> audio) {

packages/react-native-executorch/common/rnexecutorch/models/speech_to_text/stream/OnlineASRProcessor.h

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,28 @@
66

77
namespace rnexecutorch::models::speech_to_text::stream {
88

9-
using namespace asr;
10-
using namespace types;
11-
129
class OnlineASRProcessor {
1310
public:
14-
explicit OnlineASRProcessor(const ASR *asr);
11+
explicit OnlineASRProcessor(const asr::ASR *asr);
1512

1613
void insertAudioChunk(std::span<const float> audio);
17-
ProcessResult processIter(const DecodingOptions &options);
14+
types::ProcessResult processIter(const types::DecodingOptions &options);
1815
std::string finish();
1916

2017
std::vector<float> audioBuffer;
2118

2219
private:
23-
const ASR *asr;
20+
const asr::ASR *asr;
2421
constexpr static int32_t kSamplingRate = 16000;
2522

2623
HypothesisBuffer hypothesisBuffer;
2724
float bufferTimeOffset = 0.0f;
28-
std::vector<Word> committed;
25+
std::vector<types::Word> committed;
2926

30-
void chunkCompletedSegment(std::span<const Segment> res);
27+
void chunkCompletedSegment(std::span<const types::Segment> res);
3128
void chunkAt(float time);
3229

33-
std::string toFlush(const std::deque<Word> &words) const;
30+
std::string toFlush(const std::deque<types::Word> &words) const;
3431
};
3532

3633
} // namespace rnexecutorch::models::speech_to_text::stream

packages/react-native-executorch/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-executorch",
3-
"version": "0.5.4",
3+
"version": "0.5.5",
44
"description": "An easy way to run AI models in React Native with ExecuTorch",
55
"source": "./src/index.ts",
66
"main": "./lib/module/index.js",

0 commit comments

Comments
 (0)