Skip to content

Commit 091a306

Browse files
committed
update volume metering link
1 parent 637dee2 commit 091a306

File tree

4 files changed

+22
-24
lines changed

4 files changed

+22
-24
lines changed

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -548,13 +548,12 @@ You can use the `volumeChangeEventOptions.enabled` option to enable volume meter
548548

549549
![Volume metering example](./images/volume-metering.gif)
550550

551-
See: (link) for a complete example that involves using `react-native-reanimated` to animate the volume metering.
551+
See: [VolumeMeteringAvatar.tsx](https://github.com/jamsch/expo-speech-recognition/tree/main/example/components/VolumeMeteringAvatar.tsx) for a complete example that involves using `react-native-reanimated` to animate the volume metering.
552552

553-
````tsx
553+
```tsx
554554
import { ExpoSpeechRecognitionModule } from "expo-speech-recognition";
555555

556556
function VolumeMeteringAvatar() {
557-
558557
useSpeechRecognitionEvent("volumechange", (event) => {
559558
console.log("Volume changed to:", event.value);
560559
});
@@ -576,6 +575,7 @@ function VolumeMeteringAvatar() {
576575
</View>
577576
);
578577
}
578+
```
579579

580580
## Polyfilling the Web SpeechRecognition API
581581

@@ -655,7 +655,7 @@ recognition.stop();
655655

656656
// Immediately cancel speech recognition
657657
recognition.abort();
658-
````
658+
```
659659

660660
## Muting the beep sound on Android
661661

example/App.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export default function App() {
8080
],
8181
volumeChangeEventOptions: {
8282
enabled: false,
83-
intervalMillis: 100,
83+
intervalMillis: 300,
8484
},
8585
});
8686

example/components/VolumeMeteringAvatar.tsx

+17-19
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ import Animated, {
1313
const avatar = require("../assets/avatar.png");
1414

1515
const MIN_SCALE = 1;
16-
const MAX_SCALE = 1.5;
16+
const MAX_SCALE = 2;
1717

1818
/**
1919
* This is an example component that uses the `volumechange` event to animate the volume metering of a user's voice.
2020
*/
2121
export function VolumeMeteringAvatar() {
22-
const haloScale = useSharedValue(MIN_SCALE);
22+
const volumeScale = useSharedValue(MIN_SCALE);
2323
const pulseScale = useSharedValue(MIN_SCALE);
2424
const pulseOpacity = useSharedValue(0);
2525

2626
const reset = () => {
27-
haloScale.value = MIN_SCALE;
27+
volumeScale.value = MIN_SCALE;
2828
pulseScale.value = MIN_SCALE;
2929
pulseOpacity.value = 0;
3030
};
@@ -45,16 +45,14 @@ export function VolumeMeteringAvatar() {
4545
Extrapolation.CLAMP,
4646
);
4747

48-
// Animate the halo scaling
49-
haloScale.value = withSequence(
48+
// Animate the volume scaling
49+
volumeScale.value = withSequence(
5050
withSpring(newScale, {
51-
damping: 15,
51+
damping: 10,
5252
stiffness: 150,
5353
}),
54-
withTiming(MIN_SCALE, {
55-
duration: 500,
56-
easing: Easing.linear,
57-
}),
54+
// Scale back down, unless the volume changes again
55+
withTiming(MIN_SCALE, { duration: 500 }),
5856
);
5957

6058
// Animate the pulse (scale and fade out)
@@ -69,22 +67,22 @@ export function VolumeMeteringAvatar() {
6967
}
7068
});
7169

72-
const haloAnimatedStyle = useAnimatedStyle(() => ({
73-
transform: [{ scale: haloScale.value }],
70+
const volumeScaleStyle = useAnimatedStyle(() => ({
71+
transform: [{ scale: volumeScale.value }],
7472
}));
7573

76-
const pulseAnimatedStyle = useAnimatedStyle(() => ({
74+
const pulseStyle = useAnimatedStyle(() => ({
7775
opacity: pulseOpacity.value,
7876
transform: [{ scale: pulseScale.value }],
7977
}));
8078

8179
return (
8280
<View style={styles.container}>
83-
<View style={styles.pulseContainer}>
84-
<Animated.View style={[styles.halo, haloAnimatedStyle]} />
81+
<View style={styles.absoluteCenteredContainer}>
82+
<Animated.View style={[styles.circularBorder, volumeScaleStyle]} />
8583
</View>
86-
<View style={styles.pulseContainer}>
87-
<Animated.View style={[styles.pulse, pulseAnimatedStyle]} />
84+
<View style={styles.absoluteCenteredContainer}>
85+
<Animated.View style={[styles.pulse, pulseStyle]} />
8886
</View>
8987
<View style={[styles.centered]}>
9088
<Image source={avatar} style={styles.avatar} />
@@ -98,7 +96,7 @@ const styles = StyleSheet.create({
9896
position: "relative",
9997
marginVertical: 20,
10098
},
101-
pulseContainer: {
99+
absoluteCenteredContainer: {
102100
position: "absolute",
103101
top: 0,
104102
bottom: 0,
@@ -114,7 +112,7 @@ const styles = StyleSheet.create({
114112
height: 96,
115113
borderRadius: 96,
116114
},
117-
halo: {
115+
circularBorder: {
118116
backgroundColor: "#6b7280",
119117
width: 96,
120118
height: 96,

images/volume-metering.gif

-22.5 KB
Loading

0 commit comments

Comments
 (0)