← 제작기

맥에서 잰 1.48초가 기기에서는 25~31초였다

말로 대화하는 작은 기기 포키를 만들고 있습니다. 머리는 맥북(M5, 24GB)에서 도는 로컬 모델이고, 몸은 둥근 화면이 달린 ESP32-S3 보드입니다. 보드가 오기 전 맥에서 받아쓰기와 답, 음성 합성을 이어 붙여 잰 첫 소리는 가운데 값 1.48초였습니다. 질문 음성을 넘긴 순간부터 잰 값이라 기기와 맥 사이 전송은 들어 있지 않았습니다.

11월 3일 보드가 와서 처음 말을 주고받아 보니 단추를 뗀 뒤 답까지 25.3초가 걸렸습니다. 이 글은 기기를 붙인 첫 주에 맥에서 잰 값과 제 짐작이 기기 앞에서 뒤집힌 일들을 적습니다. 몇 가지는 되돌렸고, 몇 가지는 까닭을 아직 확정하지 못했습니다.

맥 안 시험에서 빨라진 것이 기기에서는 느려졌다

첫 대화의 25.3초는 받아쓰기 6.0초, 답 6.0초, 목소리 11.8초였습니다. 목소리 모델을 부를 때마다 새로 올리고 있었습니다. 목소리를 올려 둔 일꾼으로 바꾸고 마이크 이득을 30dB 에서 37.5dB 로 올리자 14.5초가 됐습니다.

다음으로 답을 문장마다 먼저 보내게 했습니다. 맥 안 시험에서는 답이 나온 뒤 첫 소리까지 7.8초가 4.3~5.0초로 줄었습니다. 같은 고침을 단 기기로 진짜 대화를 하자, 답이 71자로 길었던 그 대화는 단추를 뗀 뒤 첫 소리까지 31.0초로 오히려 늘었습니다. 맥 24GB 에 대화 모델 13.2GB, 목소리 3.3GB, 받아쓰기 2.3GB 가 올라 있었고 가상화 2.0GB 와 Claude 앱 2GB 남짓까지 더해져 스왑이 16GB 에서 18GB 로 늘었습니다. 그사이 맥 안 시험의 받아쓰기도 0.5초에서 3.1~10.5초로 흔들렸습니다.

대화 모델은 10월 19일 측정 때 7.8~8.3GB 였습니다. 다른 세션에서 AI 와 살펴보니 늘어난 몫은 모델 무게 7.7GB 위에 MLX 가 쥔 Metal 버퍼 캐시였습니다. 문맥 길이로는 줄지 않고 모델을 내려야 돌아온다는 판정이었습니다. 1.48초를 잰 맥과 기기를 붙인 날의 맥은 메모리로 보면 다른 기계였습니다. 스왑이 측정을 어떻게 흔드는지는 앞 글에 적었습니다.

메모리부터 덜었습니다. 받아쓰기를 4비트 판으로 바꾸기 전에 합성 문장 10개를 두 번씩 받아써 보니 원판과 글이 모두 같았고, 늘 차지하는 메모리는 1.62GB 에서 0.47GB 가 됐습니다. 첫 소리는 23.0초, 스왑은 9.9GB 로 내려왔습니다. 이어서 답을 조각으로 받아 끝난 문장부터 읽히고, 기기 대화에만 첫 문장을 열다섯 자 안쪽으로 쓰라고 일렀습니다. 기기의 보내기 버퍼를 5760 에서 32768 로 키우자 6초 분량 녹음을 올리는 데 약 5초 걸리던 것이 1~3.3초가 됐습니다. 마지막 판은 단추를 뗀 뒤 첫 소리 10.3~10.9초였습니다.

메모리가 덜 찼을 때 맥 안 시험의 첫 문장은 1.8~2.1초여서, 남은 지연도 메모리 탓으로 보고 있습니다. 기기 대화가 끝나면 대화 모델을 3분만 올려 두기로 제가 정했습니다. 대가는 쉬었다가 다시 말할 때 옵니다. 9분 쉬었다 말한 대화는 모델을 다시 올리는 데 6.2초가 들어 첫 소리가 23.4초였습니다.

3초대로 당긴 첫 소리를 들어 보고 되돌렸다

첫 소리를 더 당기려고 목소리 모델이 만들어 내는 0.5초 조각을 그대로 보내 봤습니다. 맥 안 시험에서 첫 소리가 8.9~10.5초에서 3.2~3.6초로 당겨졌습니다. 숫자로는 이번 주에 가장 큰 개선이었는데, 들어 보니 문장 앞부분이 조금 이상했습니다. 같은 두 문장을 0.5초 조각, 앞 무음을 자르지 않은 0.5초 조각, 1초 조각, 문장을 다 만든 뒤의 네 판으로 만들어 들어 보니 괜찮은 것은 마지막 하나뿐이었습니다. 조각 방식 자체가 문장 앞을 망친다고 보고 되돌렸고, 조각으로 내는 코드는 기록으로만 남겨 두고 쓰지 않습니다. 쉼표에서 나눠 따로 읽힌 조각마다 빠르기와 높이가 달라졌던 앞 일과 같은 쪽의 교훈입니다.

끝까지 남은 것은 기기에서만 답 앞이 살짝 끊기는 일이었습니다. 맥에서 들은 같은 판은 괜찮았습니다. 앞에 0 으로 된 무음 0.25초를 붙여도 그대로였고, 처음에는 무음을 목소리보다 먼저 보내 기기가 무음만 틀고 쉬어 버리는 실수도 했습니다. 0 대신 +1 과 -1 을 번갈아 넣은, 들리지 않을 만큼 작은 소리로 앞을 채우자 끊김이 사라졌습니다. 소리 칩(ES8311)이 디지털 무음을 보면 출력을 내렸다가 천천히 올리는 것으로 보고 있지만, 칩 설정을 들여다보지 않은 추정입니다. 지금은 답 앞과 문장 사이를 0 으로 채우지 않습니다.

기기에서 뒤집힌 짐작 둘

보드가 온 날 공장 펌웨어로 점검하다가 위쪽 PWR 단추를 2초 넘게 누르자 보드가 꺼졌습니다. 전원 칩이 끈 것으로 보고 "PWR 은 누르고 말하기에 못 쓴다"고 적은 뒤 말하기를 BOOT 단추로 옮겼습니다. 같은 날 밤 우리 펌웨어로 전원 칩 설정을 읽으니 끄는 시간은 10초였습니다. 2초에 끈 것은 공장 시연 펌웨어였습니다. 지금은 PWR 도 누르고 있는 동안 말하기이고, 10초에 꺼지기 전 9초에서 녹음을 끊고 높은 삑 소리 둘로 떼라고 알립니다. 9초 끊기와 10초 꺼짐은 아직 직접 재지 않았습니다.

와이파이 끊김도 처음에는 신호 탓으로 봤습니다. 첫 시도는 보낸 지 9초 만에 끊겨 실패했고, 그날 신호는 -69~-79dBm 사이였습니다. 같은 날 밤 11시 37분에는 신호가 -32dBm 으로 강할 때 보내려는 순간 끊겼고, 다시 붙을 때 남은 까닭 값은 공유기가 끊고 인증을 거부할 때 나오는 값이었습니다. 앞의 끊김을 신호 탓으로 본 데는 근거가 없었던 셈입니다. 공유기가 조용히 있는 기기를 내보내는 것으로 의심해 30초마다 맥에 안부를 보내게 했지만, 이것도 추정이고 효과는 아직 모릅니다. 그와 별도로 보내다 끊기면 와이파이를 10초까지 기다려 한 번 더 보내게 했고, 그날 밤 끊긴 대화는 5초 뒤 다시 붙어 답까지 받았습니다.

지시문 끝의 '지금 시각' 한 줄

메모리를 덜고 나서도 기기 대화마다 답 전에 앞 자료 1,800~2,000토큰을 3~5초 동안 읽고 있었습니다. 모델은 같은 앞부분이 다시 오면 지난번 계산을 다시 쓰니, 이어 말할 때는 이 시간이 짧아야 합니다. 중립 문장으로 재 보니 같은 앞부분 1,835토큰이 처음에는 3.84초, 그대로 다시 보내면 0.07초, 뒤에 말만 덧붙이면 0.18초였습니다. 맨 앞 한 줄만 바꾸면 다시 3.84초였습니다.

지시문 끝에 "지금은 몇 시 몇 분이다"라는 줄이 있었습니다. 이 줄이 1분마다 바뀌면서 그 뒤에 붙는 오늘 자료와 기억, 지난 대화까지 매번 처음부터 읽히고 있었습니다. 시각을 사용자 말 끝의 [지금] 줄로 옮겼습니다. 시험 폴더에서 지금 시각, 내일 요일, 오늘 날짜를 묻는 질문 셋은 옮긴 뒤에도 맞게 답했고, 1분을 넘겨 이어 물어도 앞 자료 읽기가 1.10초에서 0.28·0.30초가 됐습니다.

진짜 대화 기록으로 두 번 이어 말하자 그래도 처음부터 읽었습니다(3.9초). 그 사이 다른 요청은 없었습니다. 지난 대화 창이 말마다 두 칸씩 밀리며 앞쪽이 빠지는 것을 의심해, 창을 12개씩 한꺼번에 비우게 했습니다. 그 뒤 기기에서 세 번 이어 말하니 앞 자료 읽기가 3.6초에서 1.6초, 1.3초가 됐고 첫 문장은 4.2초에서 2.0초로 당겨졌습니다. 대가로 웹 대화에서도 앞 대화를 기억하는 양이 가끔 12개까지 줄어듭니다.

인공 시험의 0.3초만큼 줄지 않은 까닭은 확정하지 못했습니다. 인공 시험에서도 사이에 목소리를 만들면 0.30초가 0.95초로 늘어서, MLX 가 기억해 둔 앞부분을 많이 되감지 못하는 것으로 추정합니다. 모델 템플릿이 {{ .Prompt }} 하나라 Ollama 안에서 무엇을 다시 읽는지는 들여다볼 수 없었습니다.

정리하면

  • 맥 안 시험이 빨라졌다고 기기도 빨라지지는 않았습니다. 같은 고침이 맥 안 시험에서는 7.8초를 4.3~5.0초로 줄였고, 기기에서는 첫 소리를 31.0초로 늘렸습니다. 잴 때 맥 메모리가 얼마나 찼는지를 같이 적습니다.
  • 숫자로 가장 크게 줄인 것을 귀로 듣고 되돌렸습니다. 첫 소리 3초대보다 문장 앞이 온전한 쪽을 골랐습니다.
  • 맥에서 들어 괜찮던 소리가 기기에서는 끊겼습니다. 소리는 그 소리가 나는 기기에서 듣습니다.
  • 짐작은 그 짐작이 나온 조건부터 다시 봅니다. 2초 꺼짐은 공장 펌웨어의 동작이었고, 와이파이 끊김은 신호가 강할 때도 났습니다.
  • 자주 바뀌는 줄은 지시문 끝에 두지 않고 사용자 말 쪽으로 옮깁니다. 시각 한 줄이 그 뒤 2,000토큰 가까이를 매번 다시 읽게 했습니다.

I am building POKI, a small device you talk with by voice. The brain is a local model running on a MacBook (M5, 24GB), and the body is an ESP32-S3 board with a round screen. Before the board arrived, I chained transcription, answering and speech synthesis on the Mac, and the first sound came at a median of 1.48 seconds. That was measured from the moment the question audio was handed over, so it did not include the transfer between the device and the Mac.

The board arrived on November 3, and the first time I talked through it, the answer took 25.3 seconds from releasing the button. This post records how the values I had measured on the Mac, and my own guesses, were overturned once the device was actually connected, during its first week. Some I reverted, and for some I have not yet pinned down the reason.

What got faster in the Mac-only test got slower on the device

The 25.3 seconds of the first conversation were 6.0 seconds of transcription, 6.0 of answering and 11.8 of voice. The voice model was being loaded afresh on every call. Switching to a worker that keeps the voice loaded, and raising the microphone gain from 30dB to 37.5dB, brought it to 14.5 seconds.

Next I had the answer sent sentence by sentence, each one as soon as it was ready. In the Mac-only test, the time from the answer coming out to the first sound fell from 7.8 seconds to 4.3–5.0. With the same fix on the device, in a real conversation whose answer ran long at 71 characters, the time from releasing the button to the first sound rose instead, to 31.0 seconds. On the Mac's 24GB sat the conversation model at 13.2GB, the voice at 3.3GB and transcription at 2.3GB, and with virtualisation at 2.0GB and the Claude app at a little over 2GB on top, swap grew from 16GB to 18GB. Meanwhile, transcription in the Mac-only test wobbled from 0.5 seconds to 3.1–10.5 seconds.

In the October 19 measurement the conversation model had held 7.8–8.3GB. When I looked into it with AI in another session, the extra turned out to be the Metal buffer cache that MLX holds on top of the 7.7GB of model weights. The verdict was that it does not shrink with context length and is only released when the model is unloaded. In terms of memory, the Mac that measured 1.48 seconds and the Mac on the day the device was connected were different machines. How swap shakes the measurements is in an earlier post.

Memory came first. Before switching transcription to a 4-bit version, I transcribed 10 synthetic sentences twice each, and the text matched the original model every time, while the memory it holds at all times went from 1.62GB to 0.47GB. The first sound came down to 23.0 seconds, and swap to 9.9GB. Next, the answer was received in pieces and finished sentences were read out first, and for device conversations only, the model was told to keep the first sentence within fifteen characters. Enlarging the device's send buffer from 5760 to 32768 cut the upload of a 6-second recording from about 5 seconds to 1–3.3 seconds. The final version reached the first sound 10.3–10.9 seconds after releasing the button.

With memory less full, the first sentence in the Mac-only test took 1.8–2.1 seconds, so I suspect the remaining delay is down to memory as well. I decided to keep the conversation model loaded for only 3 minutes after a device conversation ends. The cost comes when you speak again after a pause. In a conversation started after a 9-minute pause, reloading the model took 6.2 seconds and the first sound came at 23.4 seconds.

I listened to a first sound pulled into the 3-second range, and reverted it

To pull the first sound in further, I tried sending the 0.5-second chunks the voice model produces as they came out. In the Mac-only test, the first sound moved from 8.9–10.5 seconds to 3.2–3.6 seconds. By the numbers it was the biggest improvement of the week, but when I listened, the start of the sentence sounded slightly off. I made the same two sentences in four versions: 0.5-second chunks, 0.5-second chunks without trimming the leading silence, 1-second chunks, and the whole sentence made first. Listening to them, only the last one was fine. Concluding that the chunking itself spoils the start of a sentence, I reverted it, and the code that outputs chunks is kept only as a record and is not used. It is the same kind of lesson as the earlier case where pieces split at commas and read separately each came out at a different speed and pitch.

What remained to the end was a slight break at the start of answers, only on the device. The same version heard on the Mac was fine. Adding 0.25 seconds of silence made of zeros in front changed nothing, and at first I also made the mistake of sending the silence before the voice, so the device played only the silence and went idle. Filling the front with a sound too quiet to hear, alternating +1 and -1 instead of 0, made the break disappear. My reading is that the audio chip (ES8311) turns its output down when it sees digital silence and then brings it back up slowly, but that is a guess made without looking into the chip's settings. Now neither the front of an answer nor the gaps between sentences are filled with 0.

Two guesses the device overturned

On the day the board arrived, while checking it with the factory firmware, holding the top PWR button for more than 2 seconds turned the board off. Assuming the power chip had cut it, I wrote down "PWR cannot be used for push-to-talk" and moved talking to the BOOT button. That night I read the power chip's settings with our own firmware, and the power-off time was 10 seconds. What had cut it at 2 seconds was the factory demo firmware. Now PWR also works as push-to-talk, and at 9 seconds, before the 10-second power-off, it stops recording and signals with two high beeps to let go. I have not yet measured the 9-second cutoff or the 10-second power-off directly.

I first blamed the Wi-Fi drops on the signal, too. The first attempt failed when the connection dropped 9 seconds into sending, and that day the signal was between -69 and -79dBm. At 11:37 the same night, the connection dropped just as it was about to send, with a strong signal of -32dBm, and the reason code left when it reconnected was the value that appears when the router disconnects a device and refuses its authentication. There had been no grounds, then, for blaming the earlier drop on the signal. Suspecting that the router drops devices that stay idle, I had the device send a check-in to the Mac every 30 seconds, but this is also a guess and its effect is not yet known. Separately, if the connection drops while sending, the device now waits up to 10 seconds for Wi-Fi and sends once more, and the conversation that dropped that night reconnected 5 seconds later and got its answer.

One "current time" line at the end of the system prompt

Even after memory was freed, every device conversation spent 3–5 seconds processing a 1,800–2,000-token prompt prefix before the answer. When the same prefix comes again, the model reuses its previous computation, so this time should be short when you keep talking. Measured with neutral sentences, the same 1,835-token prefix took 3.84 seconds the first time, 0.07 seconds when sent again unchanged, and 0.18 seconds with only a new message appended. Changing just the first line brought it back to 3.84 seconds.

At the end of the system prompt was a line saying "it is now such-and-such hour and minute". As that line changed every minute, everything attached after it, today's data, stored memories and earlier turns, was being processed from scratch every time. I moved the time into a [now] line at the end of the user's message. In the test folder, three questions asking the current time, tomorrow's weekday and today's date were still answered correctly after the move, and even when the follow-up came more than a minute later, prompt processing went from 1.10 seconds to 0.28 and 0.30 seconds.

With a real conversation log, two follow-ups were still processed from scratch (3.9 seconds). There were no other requests in between. Suspecting that the window of earlier turns was sliding by two items with each message and dropping its front, I had the window cleared 12 at a time. After that, three follow-ups on the device took prompt processing from 3.6 seconds to 1.6 and then 1.3 seconds, and the first sentence moved from 4.2 seconds to 2.0. The cost is that web conversations, too, sometimes remember as few as 12 earlier items.

I have not pinned down why it did not drop as far as the 0.3 seconds of the artificial test. In the artificial test as well, making voice in between raised 0.30 seconds to 0.95, so my guess is that MLX cannot rewind much of the prefix it has kept. The model template is a single {{ .Prompt }}, so I could not see what Ollama reprocesses inside.

In short

  • Faster in the Mac-only test did not mean faster on the device. The same fix cut 7.8 seconds to 4.3–5.0 in the Mac-only test and stretched the first sound to 31.0 seconds on the device. Now I note how full the Mac's memory was alongside each measurement.
  • I listened to the biggest numerical gain and reverted it. I chose intact sentence openings over a first sound in the 3-second range.
  • Sound that was fine heard on the Mac broke up on the device. I listen to sound on the device that will play it.
  • I re-examine a guess starting from the conditions that produced it. The 2-second power-off was the factory firmware's behaviour, and the Wi-Fi drops happened with a strong signal too.
  • Lines that change often do not go at the end of the system prompt; they move to the user's message. One time line made the model reprocess nearly 2,000 tokens after it every time.