-
Notifications
You must be signed in to change notification settings - Fork 298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bluetooth #84
base: main
Are you sure you want to change the base?
Bluetooth #84
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
import { multiParser } from 'https://deno.land/x/multiparser@0.114.0/mod.ts'; | ||
|
||
|
||
function createWavHeader(dataLength: number, sampleRate: number, numChannels: number, bitDepth: number) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this is related to the the issue you described of not being able to send the raw bytes?
Are you able to see / log the raw bytes locally on the phone?
Meaning, can you work with the bytes locally, just can't send them, or you can't even collect them as raw bytes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right.
I get raw bytes from esp32, so I can get them as raw bytes and populate an ArrayBuffer
, but sending just the array buffer over HTTP Capacitor client did not work, as in no request was made.
So instead I encoded that array buffer as base64 and sent it as part of a JSON.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see - so the header can still be managed by the client side, and just base64 the entire bytes of the wav file?
To make the breaking change smaller, or even not exists
You can add an if statement that checks if it is base64, do x else y
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added several if statements, so now it no longer is a breaking change, it will still work with form requests and binary bodies.
if (contentType.includes('multipart/form-data')) {
const form = await multiParser(req);
if (!form || !form.files || !form.files.file) {
return new Response('File not found in form', {
status: 400,
headers: corsHeaders,
});
}
console.log('Form:', form);
const file = form.files.file;
arrayBuffer = file.content.buffer;
filenameTimestamp = file.filename || filenameTimestamp;
} else if (contentType.includes('application/json')) {
const { data } = await req.json();
const audioData = decodeBase64(data);
console.log('Audio data:', audioData.length);
// 1 Channel, 8000 sample rate, 16 bit depth
const wavHeader = createWavHeader(audioData.length, 16000, 1, 16);
const wavBytes = new Uint8Array(wavHeader.length + audioData.length);
wavBytes.set(wavHeader, 0);
wavBytes.set(audioData, wavHeader.length);
arrayBuffer = wavBytes.buffer;
} else {
arrayBuffer = await req.arrayBuffer();
}
```
Adding @Jacksonmills as a reviewer to check out the frontend changes! (also, there's a merge conflict) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking decent, I think we could definitely clean up the connect page and make it more of a fleshed out page
<NewConversationButton | ||
createNewConversation={() => { | ||
newConversation.mutate(); | ||
}} | ||
/> | ||
<Button |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets make sure to use next/link Link
for these. You can use asChild
on Button
so it renders just as the <a></a>
tag and not <button><a></a></button>
e.g.
<Button
...
+ asChild
- onClick={() => router.push('/')}
>
+ <Link href="/connect">
<Bluetooth size={20} />
+ </Link>
</Button>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh and then remove the useRouter if we arent needing it anymore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we could definitely clean up the connect page and make it more of a fleshed out page
totally agree. ESP32 is still fairly unusable - high power consumption, requires soldering a mic on it, want to push out nrf PR and then polish the connect page.
<div className="from-background fixed top-0 flex h-24 w-full items-center justify-between bg-gradient-to-b"></div> | ||
<div className="fixed right-4 top-4 flex space-x-4"> | ||
<NavMenu> | ||
<Button |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as other link
app/src/pages/connect.tsx
Outdated
<Files size={20} /> | ||
</Button> | ||
<ThemeToggle /> | ||
<LogoutButton supabaseClient={supabaseClient!} /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
supabaseClient!
It's best practice to check for a null supabaseClient at the beginning of your component's render function and handle it by returning null. This prevents the rest of the function from executing with an invalid client, which is more efficient and makes the code easier to read and maintain.
if (!supabaseClient) {
return <div>Supabase client not found</div>;
}
@Jacksonmills can you take a look again? |
This is work in progress changes for bluetooth client on ios and android, this will not work on web and you will need a physical device to use this.
Changes:
I left some other comments in the code for discussion