Spaces:
Runtime error
Runtime error
Download fish_speech/datasets/protos/text_data_stream.py from codemo/fish-speech-1: direct link, hf CLI and curl.
- Browser
- Download file 781 Bytes
-
https://huggingface.co/spaces/codemo/fish-speech-1/resolve/main/fish_speech/datasets/protos/text_data_stream.py
- Command line
-
hf download hf://spaces/codemo/fish-speech-1/fish_speech/datasets/protos/text_data_stream.py
-
curl -L -o text_data_stream.py https://huggingface.co/spaces/codemo/fish-speech-1/resolve/main/fish_speech/datasets/protos/text_data_stream.py
781 Bytes
| import struct | |
| from .text_data_pb2 import TextData | |
| def read_pb_stream(f): | |
| while True: | |
| buf = f.read(4) | |
| if len(buf) == 0: | |
| break | |
| size = struct.unpack("I", buf)[0] | |
| buf = f.read(size) | |
| text_data = TextData() | |
| text_data.ParseFromString(buf) | |
| yield text_data | |
| def write_pb_stream(f, text_data): | |
| buf = text_data.SerializeToString() | |
| f.write(struct.pack("I", len(buf))) | |
| f.write(buf) | |
| def pack_pb_stream(text_data): | |
| buf = text_data.SerializeToString() | |
| return struct.pack("I", len(buf)) + buf | |
| def split_pb_stream(f): | |
| while True: | |
| head = f.read(4) | |
| if len(head) == 0: | |
| break | |
| size = struct.unpack("I", head)[0] | |
| buf = f.read(size) | |
| yield head + buf | |