Skip to content

Instantly share code, notes, and snippets.

@seflless
Created February 22, 2024 22:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seflless/86ba1eac6d3f9a2d684c2a7f7ec1d991 to your computer and use it in GitHub Desktop.
Save seflless/86ba1eac6d3f9a2d684c2a7f7ec1d991 to your computer and use it in GitHub Desktop.
socket.on("server-text-to-speech") {data, ack in
print("server-text-to-speech")
// The data structure for this message type is here:
// https://github.com/descriptinc/descript-web-v2/blob/staging/pkg-js/brain-buddy-protocol/src/ServerSentEvents.ts#L27-L48
if let firstItem = data.first as? [String: Any],
guard let progress = firstItem["progress"] as? String else {
return
}
if progress == "first" {
// First packet of text to speech
}
// All messages except ones with progress=='final' have an audioChunk associated
if progress != "final" {
let bytes = firstItem["audioChunk"] as? Data { // Assuming 'audioChunk' is of type Data
self.aacBuffer.append(bytes);
}
if progress == 'final' {
// No more text to speech audio is coming.
}
} else {
print("Key not found in dictionary, or data format not as expected.")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment