You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying alignment, the node client works. But having issue with doing it in python. I tried sending in base64 data for audio, it broke, couldn't pass bytes serialized for json.
import asyncio
import websockets
import json
from pydub import AudioSegment
async def align_audio():
async with websockets.connect('ws://localhost:45054') as ws:
print('Connected to the WebSocket server')
audio = AudioSegment.from_file(
'./audio-files/event_24ce4d18-feb0-4de6-acf4-0eac5ae9ff03.mp3', format='mp3')
raw_audio = audio.raw_data
sample_rate = audio.frame_rate
channels = audio.channels
request = {
'messageType': 'AlignmentRequest',
'requestId': 'some-unique-request-id',
'input': {
'audioChannels': [raw_audio],
'sampleRate': sample_rate
},
'transcript': 'Watson, we have a most intriguing case on our hands. The Tinderbox Killer has struck again, leaving behind his chilling signature - a small wooden matchbox containing a single match.',
'options': {
'language': 'en-US'
}
}
await ws.send(json.dumps(request))
response = await ws.recv()
alignment_result = json.loads(response)
print('Alignment result:', alignment_result)
with open('alignment_result.json', 'w') as file:
json.dump(alignment_result, file)
print('Alignment result saved to alignment_result.json')
print('Disconnected from the WebSocket server')
if __name__ == '__main__':
asyncio.run(align_audio())
The text was updated successfully, but these errors were encountered:
Apply the MessagePack encoding over your entire message, and in the same way, decode the entire binary message sent back from the WebSocket using MessagePack.
I chose to use a full binary encoding of the entire message since makes it more flexible and easier to implement than needing to serialize / deserialize individual object properties. Also it's more uniform since all WebSocket messages are binary, and there's no need to consider text messages at all.
I am trying alignment, the node client works. But having issue with doing it in python. I tried sending in base64 data for audio, it broke, couldn't pass bytes serialized for json.
The text was updated successfully, but these errors were encountered: