Skip to content

Commit

Permalink
Simplify the convert_rnnoise script
Browse files Browse the repository at this point in the history
Instead of calling a function for every weight, do the modulo
immediately while converting the data, and insert directly in the
bytearray instead of allocating an intermediary list.
  • Loading branch information
linkmauve committed Nov 9, 2024
1 parent 3f5281f commit d02af28
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions train/convert_rnnoise.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,11 @@
sys.exit(1)

data = in_file.read()
in_nums = [int(s) for s in data.split()]

# Convert to an unsigned byte (which, in twos complement, represents the same number)
def cvt(n):
if n < 0:
return 256 + n
else:
return n

nums = [cvt(n) for n in in_nums]
nums = bytearray(int(s) % 256 for s in data.split())

with open(out_name, 'wb') as out_file:
out_file.write(bytearray(nums))
out_file.write(nums)

print(f'Converted {in_name} to {out_name}')

0 comments on commit d02af28

Please sign in to comment.