diff --git a/packages/embeds/js/package.json b/packages/embeds/js/package.json
index 9eabc85ca..fdb893f1f 100644
--- a/packages/embeds/js/package.json
+++ b/packages/embeds/js/package.json
@@ -1,6 +1,6 @@
{
"name": "@typebot.io/js",
- "version": "0.3.10",
+ "version": "0.3.11",
"description": "Javascript library to display typebots on your website",
"type": "module",
"main": "dist/index.js",
diff --git a/packages/embeds/js/src/components/Bot.tsx b/packages/embeds/js/src/components/Bot.tsx
index f13cd5dad..6f42c4394 100644
--- a/packages/embeds/js/src/components/Bot.tsx
+++ b/packages/embeds/js/src/components/Bot.tsx
@@ -294,7 +294,6 @@ const BotContent = (props: BotContentProps) => {
onMount(() => {
if (!botContainerElement) return
- console.log('yes')
setBotContainer(botContainerElement)
resizeObserver.observe(botContainerElement)
setBotContainerHeight(`${botContainerElement.clientHeight}px`)
diff --git a/packages/embeds/js/src/components/InputChatBlock.tsx b/packages/embeds/js/src/components/InputChatBlock.tsx
index 725de233d..78becfdbb 100644
--- a/packages/embeds/js/src/components/InputChatBlock.tsx
+++ b/packages/embeds/js/src/components/InputChatBlock.tsx
@@ -59,7 +59,6 @@ export const InputChatBlock = (props: Props) => {
})
const handleSubmit = async (content: InputSubmitContent) => {
- console.log(content)
setAnswer(content)
props.onSubmit(content)
}
diff --git a/packages/embeds/js/src/components/bubbles/GuestBubble.tsx b/packages/embeds/js/src/components/bubbles/GuestBubble.tsx
index efb500305..b53d2704f 100644
--- a/packages/embeds/js/src/components/bubbles/GuestBubble.tsx
+++ b/packages/embeds/js/src/components/bubbles/GuestBubble.tsx
@@ -127,12 +127,12 @@ const TextGuestBubble = (props: { answer: TextInputSubmitContent }) => {
const AudioGuestBubble = (props: { answer: RecordingInputSubmitContent }) => {
return (
-
+
)
diff --git a/packages/embeds/js/src/features/blocks/inputs/textInput/components/TextInput.tsx b/packages/embeds/js/src/features/blocks/inputs/textInput/components/TextInput.tsx
index 8534862f2..56eb96a44 100644
--- a/packages/embeds/js/src/features/blocks/inputs/textInput/components/TextInput.tsx
+++ b/packages/embeds/js/src/features/blocks/inputs/textInput/components/TextInput.tsx
@@ -216,7 +216,9 @@ export const TextInput = (props: Props) => {
{
let stream: MediaStream | undefined
let bars: number[] = []
let recordTimeInterval: NodeJS.Timer | undefined
- let lastFrameTime: DOMHighResTimeStamp | undefined
+ let lastFrameTime: DOMHighResTimeStamp | undefined = undefined
+ let offset = 0
const fillRgb = hexToRgb(
props.buttonsTheme?.backgroundColor ?? defaultButtonsBackgroundColor
).join(', ')
- const animate = () => {
+ const draw = () => {
if (!ctx || !canvasElement || !lastFrameTime) return
const currentTime = performance.now()
@@ -72,25 +74,22 @@ export const VoiceRecorder = (props: Props) => {
offset += dx * (deltaTime / 1000)
- animationFrameId = requestAnimationFrame(animate)
+ animationFrameId = requestAnimationFrame(draw)
}
const startRecording = async () => {
if (!canvasElement) return
- if (!ctx) ctx = canvasElement.getContext('2d') ?? undefined
-
- lastFrameTime = performance.now()
-
- animate()
-
- recordTimeInterval = setInterval(() => {
- setRecordingTime((prev) => (prev += 1))
- }, 1000)
stream = await navigator.mediaDevices.getUserMedia({ audio: true })
props.onRecordingConfirmed(stream)
+ if (!ctx) ctx = canvasElement.getContext('2d') ?? undefined
+
+ recordTimeInterval = setInterval(() => {
+ setRecordingTime((prev) => (prev += 1))
+ }, 1000)
+
audioContext = new AudioContext()
volumeNode = await loadVolumeProcessorWorklet(audioContext)
@@ -100,8 +99,21 @@ export const VoiceRecorder = (props: Props) => {
volumeNode.connect(audioContext.destination)
volumeNode.port.onmessage = (event) => {
- bars.push(event.data)
+ const initBars = (canvasElement.width + barGap) / (barWidth + barGap)
+ const shouldAddNewBar =
+ (initBars + bars.length) * (barWidth + barGap) <
+ canvasElement.width + offset
+ if (shouldAddNewBar)
+ bars.push(
+ Math.min(
+ Math.max(event.data, minDetectedVolumePercent),
+ maxDetectedVolumePercent
+ )
+ )
}
+
+ lastFrameTime = performance.now()
+ animationFrameId = requestAnimationFrame(draw)
}
const stopRecording = () => {
@@ -156,9 +168,11 @@ export const VoiceRecorder = (props: Props) => {
-
{formatTimeLabel(recordingTime())}
+
+ {formatTimeLabel(recordingTime())}
+
)
}
diff --git a/packages/embeds/js/src/features/blocks/inputs/textInput/components/VolumeProcessor.ts b/packages/embeds/js/src/features/blocks/inputs/textInput/components/VolumeProcessor.ts
index 4375e6886..5d0661092 100644
--- a/packages/embeds/js/src/features/blocks/inputs/textInput/components/VolumeProcessor.ts
+++ b/packages/embeds/js/src/features/blocks/inputs/textInput/components/VolumeProcessor.ts
@@ -1,19 +1,13 @@
export const volumeProcessorCode = `
-const throttleMs = 110;
-const maxVolumePercent = 80;
-const volumeMultiplier = 3;
+const gainFactor = 3;
class VolumeProcessor extends AudioWorkletProcessor {
constructor() {
super();
- this.lastUpdateTime = 0;
- this.volumeSum = 0;
- this.volumeCount = 1;
}
process(inputs) {
const input = inputs[0];
- const currentTime = new Date().getTime();
if (input.length > 0) {
const channelData = input[0];
let sum = 0;
@@ -21,16 +15,7 @@ class VolumeProcessor extends AudioWorkletProcessor {
sum += channelData[i] * channelData[i];
}
const rms = Math.sqrt(sum / channelData.length);
- const volumePercent = rms * 100;
- this.volumeSum += volumePercent;
- this.volumeCount += 1;
- }
- if (currentTime - this.lastUpdateTime >= throttleMs) {
- const averageVolume = 1 + this.volumeSum / this.volumeCount;
- this.port.postMessage(Math.min(averageVolume * volumeMultiplier, maxVolumePercent));
- this.volumeSum = 0;
- this.volumeCount = 1;
- this.lastUpdateTime = currentTime;
+ this.port.postMessage(rms * 100 * gainFactor)
}
return true;
}
diff --git a/packages/embeds/nextjs/package.json b/packages/embeds/nextjs/package.json
index a600f986a..4dd431a0e 100644
--- a/packages/embeds/nextjs/package.json
+++ b/packages/embeds/nextjs/package.json
@@ -1,6 +1,6 @@
{
"name": "@typebot.io/nextjs",
- "version": "0.3.10",
+ "version": "0.3.11",
"description": "Convenient library to display typebots on your Next.js website",
"main": "dist/index.js",
"types": "dist/index.d.ts",
diff --git a/packages/embeds/react/package.json b/packages/embeds/react/package.json
index a4db2a33c..9101b035f 100644
--- a/packages/embeds/react/package.json
+++ b/packages/embeds/react/package.json
@@ -1,6 +1,6 @@
{
"name": "@typebot.io/react",
- "version": "0.3.10",
+ "version": "0.3.11",
"description": "Convenient library to display typebots on your React app",
"main": "dist/index.js",
"types": "dist/index.d.ts",