Skip to content

Commit 63086e6

Browse files
committed
Fix bug in generate for Android
1 parent 7b2e2f7 commit 63086e6

5 files changed

Lines changed: 20 additions & 6 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ React Native autolinking handles Android integration after the package is instal
2626

2727
## Quick start
2828

29-
Your `modelId` is the **Model Credential** shown in your Wfloat account after purchase.
29+
Your `modelId` is the **Model Credential** shown in your Wfloat account after sign up.
3030

3131
```tsx
3232
import { SpeechClient } from "@wfloat/react-native-wfloat";

android/src/main/java/com/wfloat/WfloatAudioSession.kt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ internal class WfloatAudioSession(
2727
) -> Unit,
2828
private val playbackFinishedHandler: (requestId: Int) -> Unit,
2929
) {
30+
companion object {
31+
private const val BYTES_PER_PCM_FLOAT_SAMPLE = 4
32+
}
33+
3034
private data class AudioWriteItem(
3135
val samples: FloatArray,
3236
)
@@ -69,12 +73,19 @@ internal class WfloatAudioSession(
6973
private var totalFramesScheduled = 0L
7074

7175
init {
76+
require(sampleRate > 0) { "Invalid sample rate: $sampleRate" }
77+
7278
val minBufferSize = AudioTrack.getMinBufferSize(
7379
sampleRate,
7480
AudioFormat.CHANNEL_OUT_MONO,
7581
AudioFormat.ENCODING_PCM_FLOAT
7682
)
77-
val bufferSize = max(minBufferSize, sampleRate / 2)
83+
require(minBufferSize > 0) {
84+
"Failed to determine minimum audio buffer size for sample rate $sampleRate."
85+
}
86+
87+
val targetBufferSizeBytes = (sampleRate * BYTES_PER_PCM_FLOAT_SAMPLE) / 2
88+
val bufferSize = max(minBufferSize, targetBufferSizeBytes)
7889

7990
val attributes = AudioAttributes.Builder()
8091
.setContentType(AudioAttributes.CONTENT_TYPE_SPEECH)
@@ -94,6 +105,9 @@ internal class WfloatAudioSession(
94105
AudioTrack.MODE_STREAM,
95106
AudioManager.AUDIO_SESSION_ID_GENERATE
96107
)
108+
require(track.state == AudioTrack.STATE_INITIALIZED) {
109+
"Failed to initialize AudioTrack for sample rate $sampleRate and buffer size $bufferSize."
110+
}
97111
track.play()
98112

99113
playbackThread = Thread(

example/ios/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,7 +1263,7 @@ PODS:
12631263
- ReactCommon/turbomodule/bridging
12641264
- ReactCommon/turbomodule/core
12651265
- Yoga
1266-
- react-native-wfloat (0.2.0):
1266+
- react-native-wfloat (1.0.1):
12671267
- DoubleConversion
12681268
- glog
12691269
- hermes-engine
@@ -1797,7 +1797,7 @@ SPEC CHECKSUMS:
17971797
React-Mapbuffer: 7eb5d69e1154e7743487ef0c8d7261e5b59afb32
17981798
React-microtasksnativemodule: 01dd998649ff5f8814846b7eee84c4d57f5d3671
17991799
react-native-blob-util: 5c9cd69d650932ed699ed51fe026a55aeb070bca
1800-
react-native-wfloat: 298fb67b1ac6bdc87a311913e8a575a809b3b8dd
1800+
react-native-wfloat: 076194cc23745e5c1e69f4cae645010e0a470d53
18011801
React-nativeconfig: f7ab6c152e780b99a8c17448f2d99cf5f69a2311
18021802
React-NativeModulesApple: 9aeb901b9bfcc9235e912445fb3cf4780a99baf4
18031803
React-perflogger: 16e049953d21b37e9871ddf0b02f414e12ff14ba

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@wfloat/react-native-wfloat",
3-
"version": "1.0.0",
3+
"version": "1.0.2",
44
"description": "Wfloat package for react native",
55
"source": "./src/index.tsx",
66
"main": "./lib/commonjs/index.js",

src/modelAssets.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export type ModelAssetsResponse = {
88
};
99

1010
const MODEL_ASSET_HOST = 'https://wfloat.com';
11-
const WFLOAT_REACT_NATIVE_VERSION = '0.2.0';
11+
const WFLOAT_REACT_NATIVE_VERSION = '1.0.2';
1212

1313
function getModelAssetPlatform(): string {
1414
switch (Platform.OS) {

0 commit comments

Comments
 (0)