3.6.Development Notes
1. Common Problem Troubleshooting
| Problem | Cause | Solution |
|---|---|---|
| Cannot connect to x86 | Wrong IP or port | Check if 192.168.41.1:10097 is accessible |
| ASR recognition returns empty | Audio too small or invalid | Increase microphone volume, check VAD status |
| No audio stream available | No face detected in front of the robot | The microphone array on the RK3588s used by TienKung has directional audio capture, covering approximately a 60-degree conical region in front of the microphone array. During conversation, the sound source must be within this region (i.e., the speaker must be within this spatial range); otherwise, the microphone array will not capture the audio |
| LLM no response | Ollama not started | Run ollama serve to start Ollama |
| TTS no sound | PyAudio device error | Check audio output device, run python -c "import pyaudio; print(pyaudio.PyAudio().get_default_output_device_info())" |
2. Performance Optimization Suggestions
# 1. Reduce log output
# Change LOG_LEVEL in log_config.py to WARNING
# 2. Adjust LLM response speed
# Use smaller model: ollama pull qwen2.5:0.5b
# 3. Optimize TTS quality
# Adjust synthesis parameters in PiperProvider
# 4. Increase ROS queue size
self.create_subscription(
AudioFrame,
'audio_sentence_frames',
callback,
10 # Increase this number to hold more messages
)
3. Steps to Add New Features
Example: Add Conversation Text Logging Feature
import json
from datetime import datetime
class ConversationLogger:
def __init__(self, log_file="conversations.jsonl"):
self.log_file = log_file
def log_turn(self, question: str, answer: str):
"""Log a conversation turn"""
record = {
"timestamp": datetime.now().isoformat(),
"question": question,
"answer": answer
}
with open(self.log_file, 'a', encoding='utf-8') as f:
f.write(json.dumps(record, ensure_ascii=False) + '\n')
# Use in tk_audio_process.py
logger = ConversationLogger()
def on_answer_complete(question, answer):
logger.log_turn(question, answer)
4. Unit Testing Example
import unittest
class TestFunASRClient(unittest.TestCase):
def setUp(self):
self.client = FunASRClient(
host="192.168.41.1",
port=10097
)
def test_to_text_with_valid_audio(self):
"""Test valid audio recognition"""
# Read test audio
with open("test_audio.pcm", "rb") as f:
audio_bytes = f.read()
# Recognize
result = self.client.to_text(audio_bytes)
# Verify result
self.assertIsNotNone(result)
self.assertGreater(len(result), 0)
def test_to_text_with_empty_audio(self):
"""Test empty audio"""
result = self.client.to_text(b"")
self.assertEqual(result, "")
if __name__ == '__main__':
unittest.main()