Closed eedeebee closed 9 months ago
Sorry this bug was in a fork of the project that didn't have its ownn issues. Closing.
Dont know why you close ? @eedeebee . I run into this problem too. This is my code in expo :
import { StatusBar } from "expo-status-bar";
import { useEffect, useState } from "react";
import { Button, PermissionsAndroid, Platform, StyleSheet, Text, View } from "react-native";
import LiveAudioStream from "react-native-live-audio-stream";
const requestMicrophonePermission = async () => {
if (Platform.OS === "android") {
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.RECORD_AUDIO,
{
title: "Microphone Permission",
message: "App needs access to your microphone to record audio.",
buttonNeutral: "Ask Me Later",
buttonNegative: "Cancel",
buttonPositive: "OK",
}
);
return granted === PermissionsAndroid.RESULTS.GRANTED;
} catch (err) {
console.warn(err);
return false;
}
}
return true;
};
export default function App() {
const [isStreaming, setIsStreaming] = useState(false);
useEffect(() => {
(async () => {
const hasPermission = await requestMicrophonePermission();
if (!hasPermission) {
alert("Microphone permission is required to use this feature.");
}
})();
}, []);
const startStreaming = () => {
console.log(LiveAudioStream)
LiveAudioStream.init({
sampleRate: 16000, // default is 44100 but it's best to have a lower one for better performance.
channels: 1, // 1 or 2, defaults to 1
bitsPerSample: 16, // 8 or 16, defaults to 16
audioSource: 6, // android only (see below)
bufferSize: 4096, // default is 2048
});
LiveAudioStream.start();
setIsStreaming(true);
};
const stopStreaming = () => {
LiveAudioStream.stop();
setIsStreaming(false);
};
return (
<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
<Text>Live Audio Stream Example</Text>
<Button
title={isStreaming ? "Stop Streaming" : "Start Streaming"}
onPress={isStreaming ? stopStreaming : startStreaming}
/>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
alignItems: "center",
justifyContent: "center",
},
});
Here's my code (or the relevant pieces of it) using RN 0.72 on an Android:
When I hit start I see: