audio playback
This commit is contained in:
parent
13cf7d4170
commit
e8bb64e56a
3 changed files with 44 additions and 9 deletions
|
|
@ -33,7 +33,7 @@ const updateRecorder = (_event, payload: boolean): void => {
|
|||
ipcMain.removeAllListeners('update-recorder');
|
||||
ipcMain.on('update-recorder', updateRecorder);
|
||||
|
||||
// utility function used by play func.
|
||||
// Split Buffer into an array of len-sized Buffers.
|
||||
function bufSplit(buf: Buffer, len: number): Array<Buffer> {
|
||||
let chunks = [];
|
||||
let i = 0;
|
||||
|
|
@ -75,19 +75,19 @@ export function initAudioIO(): void {
|
|||
}
|
||||
|
||||
// play audio buffers.
|
||||
export function play(input: string): void {
|
||||
export function play(input: Buffer): void {
|
||||
let i = 0;
|
||||
console.log(Buffer.from(input, encoding));
|
||||
// format buffers into half their size to account for writable highwaterMark.
|
||||
const audio = bufSplit(Buffer.from(input), 8192);
|
||||
console.log(audio);
|
||||
|
||||
const audio = bufSplit(input, 8192);
|
||||
|
||||
// call this fuction after last audio chunk has been written.
|
||||
const callback = () => {
|
||||
// TODO: clear portAudio writable buffer on write end.
|
||||
}
|
||||
|
||||
write();
|
||||
// iterate through audio array and write buffers to portAudio writable.
|
||||
|
||||
// Iterate through audio array and write buffers to portAudio writable.
|
||||
function write() {
|
||||
let chunk: Buffer;
|
||||
let ok = true;
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ let socket: WebSocket;
|
|||
let success = false;
|
||||
let auth = false;
|
||||
|
||||
|
||||
const authSession = async (_event, payload: string | UserCreds | null): Promise<string> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
|
|
@ -60,6 +61,17 @@ const authSession = async (_event, payload: string | UserCreds | null): Promise<
|
|||
});
|
||||
};
|
||||
|
||||
// function parseHexString(str: string) {
|
||||
// var result = [];
|
||||
// while (str.length >= 8) {
|
||||
// result.push(parseInt(str.substring(0, 8), 16));
|
||||
|
||||
// str = str.substring(8, str.length);
|
||||
// }
|
||||
|
||||
// return result;
|
||||
// }
|
||||
|
||||
const receiveMessage = (message: string): void => {
|
||||
|
||||
while (!auth) {
|
||||
|
|
@ -67,12 +79,16 @@ const receiveMessage = (message: string): void => {
|
|||
return;
|
||||
}
|
||||
|
||||
// Parse the message.
|
||||
const parsed: RenderMessage = JSON.parse(message);
|
||||
console.log('message received', parsed.content.text);
|
||||
|
||||
// If there is audio, play it.
|
||||
if (parsed.content.audio) {
|
||||
console.log('audio received');
|
||||
play(parsed.content.audio);
|
||||
const audioBytes = Buffer.from(parsed.content.audio, 'hex');
|
||||
play(audioBytes);
|
||||
}
|
||||
|
||||
backgroundMitt.emit('ipc-renderer', {
|
||||
endpoint: 'render-message',
|
||||
message: parsed
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
<template>
|
||||
Input Item Content
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
|
||||
import { defineComponent, onMounted, ref, onUnmounted } from "vue";
|
||||
import { calcSideProximity, calcPosition } from "./helpers"
|
||||
|
||||
export default defineComponent({
|
||||
|
||||
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
||||
</style>
|
||||
Loading…
Reference in a new issue