Ahh thank you!! Ping me when they release, I’d love to include them on the website! :-0
now give it a form
Can you add this to your website? (The see sammy in action?)
PFFFT of course!! It should be up now ![]()
Yaay thx
Hey @randomuser can you add this to your website?
Mine too lol
That’s a tip I’m gonna want to use to send a project example for SAMMY’s website.
This is by far the best extension on makecode! This is going on my Extension Awards List.
This is the only one I can kinda make out. gives me the IBM “daisy bell“ vibes (they made a computer IBM 7094 sing daisy bell)
@randomuser Could I add this to something like a string of text? creating a small project here and was wondering if I could use this on the story extension?
is It just me or is it talking in Morse code
Makecode Game Awards “Best Extension Award”: am i a joke to you
Hey everyone!! ![]()
I’m working on a HUGE update to the SAMMY extension. There will be no more manual phonetic writing (You can just type normally and the program will pronounce it correctly, like google translate) and I’m looking into a way of having that conversion in makecode rather than on my website.
The problem I’m trying to solve is that the data set of words and their pronunciations is HUGE (Over 130,000 lines of text, 3.6 Megabytes of plain text) so just storing it in the extension would take up a ton of storage.
However, I heard of this cool compression trick MakeCode uses…
It should mean that if there’s an unused function in a user’s code, it isn’t compiled and won’t affect the storage.
The wiki page linked mentions it is used on functions, so my idea on how to use this technique would be to load all of the text used in the program into one used function and leave the rest in an unused function that won’t be compiled, but I’m not sure how to do that in MakeCode.
Do any of you know if this could be applied to a data set? (And @richard @WoofWoof for good measure
)
Ehhhhhhhhh well… no…? You would have to have each word be… its own function wouldn’t you? Like, you can’t live edit the function code as the user types to make the function only contain the words they type. If you could change Makecode source code you totally could, because that’s how tilemap files and music files are done, but right now that’s probably not possible, unless you make each word its own function ofc, which… I have a feeling would completely crash makecode, especially if you made them all into blocks. \
Idk, maybe Richard will have some secret knowledge that I don’t have?
unfortunately, there isn’t a way to do this the way you want. i don’t know exactly how your data is stored, but let’s say you are trying to store a bunch of individual syllables, for example:
function syllable1() {
return hex`ABCD`
}
function syllable2() {
return hex`1234`
}
function syllable3() {
return hex`5678`
}
if you don’t reference one of these functions, it will indeed be left out of the compiled project because of tree shaking. that’s great, but if you want to have a single function that takes in some text and spits out syllable data, you’re going to end up writing a function like this:
function playText(text: string) {
const parsedSyllables = splitSyllables(text);
const soundData = [];
for (const syllable of text) {
switch (syllable) {
case 1: soundData.push(syllable1()); break;
case 2: soundData.push(syllable2()); break;
case 3: soundData.push(syllable3()); break;
}
}
playSyllables(soundData)
}
…and unfortunately you have just written a function that references every one of your data functions so none of them will be removed by tree shaking. our compiler doesn’t have the ability to know that the text passed into this function will never trigger the syllable1 case, so it has no choice but to include all of them in the compiled project.
Ahhh, yeah, that makes sense-- thank you for the explanation!
Are there any other compression methods used on the projects? I’ll also look into storing the syllables as hex like in your example or another form of lossless compression ![]()
MakeCode runs on limited hardware (micro:bit, Arcade consoles, etc.), so you don’t have access to heavy compression libraries like you would in Python or C. But you can still implement lightweight, lossless techniques. You could try looping words (la×4) or compressing words, which uses references (indexes) instead of full text.
if the data you’re including in your extension is lots of number arrays, then you should absolutely use buffers instead. they are way more efficient than arrays in terms of both memory usage and code size. however, if your data is a bunch of strings or images then you probably won’t gain anything by converting them to hex buffers.
here’s a little bit of code to get you started if you do have some number arrays you want to convert. this code will convert a number array into the string representation of a hex buffer and print it out in the console:
const hexChars = "0123456789ABCDEF";
const testValues = [1, 2, 3, 4];
console.log(convertNumberArrayToHex(testValues));
function convertNumberArrayToHex(values: number[]) {
// you can change this variable to control how many bytes you need
// for each number in your array. ask yourself, what is the range of
// the values i'm trying to store? are there no negative numbers? if so,
// use unsigned integers instead of signed (UInt instead of Int). do you need
// the full range of 32 bit numbers? for example, if the range of
// numbers is less than -32768..32767 for signed integers or 0..65535 for
// unsigned integers, use the 16 bit option instead of 32 bit to save
// double the space! does your code use floating point numbers? then
// consider converting them to fixed point numbers instead if possible!
const numberFormat = NumberFormat.UInt32LE;
const bytesPerNumber = Buffer.sizeOfNumberFormat(numberFormat);
const buffer = control.createBuffer(bytesPerNumber * values.length);
for (let i = 0; i < values.length; i++) {
buffer.setNumber(numberFormat, i * bytesPerNumber, values[i]);
}
return bufferToString(buffer);
}
function bufferToString(buf: Buffer) {
let bytes = "";
for (let i = 0; i < buf.length; i++) {
bytes += toHex(buf[i]);
}
return `hex\`${bytes}\``;
}
function toHex(byte: number) {
return hexChars.charAt(byte >> 4) + hexChars.charAt(byte & 0xf);
}
note that the above code is just meant for you to use as a script to convert the buffers you already have, you should not run this code at runtime. in other words, this code should not be anywhere in your extension at the end of the day!
a new great topic nice