鸿蒙智能宠物喂食提醒系统开发指南 原创

进修的泡芙
发布于 2025-6-22 16:42
浏览
0收藏

鸿蒙智能宠物喂食提醒系统开发指南

一、系统架构设计

基于HarmonyOS的AI能力和分布式技术,我们设计了一套智能宠物喂食提醒系统,主要功能包括:
声音识别:通过麦克风采集宠物叫声并识别饥饿状态

喂食记录:记录宠物喂食时间和食量

多设备协同:跨设备同步宠物状态和喂食记录

智能提醒:根据宠物习惯和健康数据提供喂食建议

远程控制:通过多设备远程控制喂食器

!https://example.com/harmony-pet-feeder-arch.png

二、核心代码实现
音频采集服务

// PetAudioService.ets
import audio from ‘@ohos.multimedia.audio’;

class PetAudioService {
private static instance: PetAudioService;
private audioCapturer: audio.AudioCapturer | null = null;
private isRecording: boolean = false;

private constructor() {}

public static getInstance(): PetAudioService {
if (!PetAudioService.instance) {
PetAudioService.instance = new PetAudioService();
return PetAudioService.instance;

public async startRecording(callback: (audioData: ArrayBuffer) => void): Promise<void> {

if (this.isRecording) return;

const audioStreamInfo: audio.AudioStreamInfo = {
  samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_16000,
  channels: audio.AudioChannel.CHANNEL_1,
  sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE,
  encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
};

const audioCapturerInfo: audio.AudioCapturerInfo = {
  source: audio.SourceType.SOURCE_TYPE_MIC,
  capturerFlags: 0
};

this.audioCapturer = await audio.createAudioCapturer({
  audioStreamInfo,
  audioCapturerInfo
});

await this.audioCapturer.start();
this.isRecording = true;

const bufferSize = await this.audioCapturer.getBufferSize();
const buffer = new ArrayBuffer(bufferSize);

while (this.isRecording) {
  const readResult = await this.audioCapturer.read(buffer);
  if (readResult > 0) {
    callback(buffer.slice(0, readResult));

await new Promise(resolve => setTimeout(resolve, 100));

}

public async stopRecording(): Promise<void> {
if (!this.isRecording || !this.audioCapturer) return;

this.isRecording = false;
await this.audioCapturer.stop();
await this.audioCapturer.release();
this.audioCapturer = null;

}

export const petAudioService = PetAudioService.getInstance();

宠物声音识别服务

// PetSoundRecognitionService.ets
import http from ‘@ohos.net.http’;

class PetSoundRecognitionService {
private static instance: PetSoundRecognitionService;
private httpClient: http.HttpRequest;
private apiKey = ‘YOUR_PET_SOUND_API_KEY’;

private constructor() {
this.httpClient = http.createHttp();
public static getInstance(): PetSoundRecognitionService {

if (!PetSoundRecognitionService.instance) {
  PetSoundRecognitionService.instance = new PetSoundRecognitionService();

return PetSoundRecognitionService.instance;

public async recognizePetSound(audioData: ArrayBuffer): Promise<PetSoundResult> {

const formData = new FormData();
formData.append('audio', new Blob([audioData], { type: 'audio/wav' }));
formData.append('api_key', this.apiKey);

return new Promise((resolve, reject) => {
  this.httpClient.request(
    'https://pet-sound-api.example.com/recognize',

method: ‘POST’,

      header: { 'Content-Type': 'multipart/form-data' },
      extraData: formData
    },
    (err, data) => {
      if (err) {
        reject(err);

else {

        const result = JSON.parse(data.result);
        resolve(this.processSoundResult(result));

}

  );
});

private processSoundResult(rawData: any): PetSoundResult {

return {
  petType: rawData.petType || '未知宠物',
  soundType: rawData.soundType || '未知声音',
  isHungry: rawData.isHungry || false,
  confidence: rawData.confidence || 0,
  timestamp: Date.now()
};

}

export const petSoundService = PetSoundRecognitionService.getInstance();

多设备喂食同步服务

// PetFeedingSyncService.ets
import distributedData from ‘@ohos.data.distributedData’;
import deviceManager from ‘@ohos.distributedHardware.deviceManager’;

class PetFeedingSyncService {
private static instance: PetFeedingSyncService;
private kvManager: distributedData.KVManager;
private kvStore: distributedData.KVStore;

private constructor() {
this.initKVStore();
private async initKVStore(): Promise<void> {

const config = {
  bundleName: 'com.example.petFeeder',
  userInfo: { userId: 'currentUser' }
};

this.kvManager = distributedData.createKVManager(config);
this.kvStore = await this.kvManager.getKVStore('pet_feeding_store', {
  createIfMissing: true
});

this.kvStore.on('dataChange', (data) => {
  this.handleRemoteUpdate(data);
});

public static getInstance(): PetFeedingSyncService {

if (!PetFeedingSyncService.instance) {
  PetFeedingSyncService.instance = new PetFeedingSyncService();

return PetFeedingSyncService.instance;

public async syncFeedingRecord(record: FeedingRecord): Promise<void> {

await this.kvStore.put(feeding_${record.id}, JSON.stringify(record));

public async getFeedingRecords(petId: string): Promise<FeedingRecord[]> {

const entries = await this.kvStore.getEntries('feeding_');
return Array.from(entries)
  .map(([_, value]) => JSON.parse(value))
  .filter(record => record.petId === petId);

public async syncPetProfile(pet: PetProfile): Promise<void> {

await this.kvStore.put(pet_${pet.id}, JSON.stringify(pet));

public async getPetProfile(petId: string): Promise<PetProfile | null> {

const value = await this.kvStore.get(pet_${petId});
return value ? JSON.parse(value) : null;

private handleRemoteUpdate(data: distributedData.ChangeInfo): void {

if (data.deviceId === deviceInfo.deviceId) return;

const key = data.key as string;
if (key.startsWith('feeding_')) {
  const record = JSON.parse(data.value);
  EventBus.emit('feedingRecordUpdated', record);

else if (key.startsWith(‘pet_’)) {

  const pet = JSON.parse(data.value);
  EventBus.emit('petProfileUpdated', pet);

}

export const petSyncService = PetFeedingSyncService.getInstance();

喂食建议服务

// FeedingAdviceService.ets
class FeedingAdviceService {
private static instance: FeedingAdviceService;

private constructor() {}

public static getInstance(): FeedingAdviceService {
if (!FeedingAdviceService.instance) {
FeedingAdviceService.instance = new FeedingAdviceService();
return FeedingAdviceService.instance;

public async getFeedingAdvice(pet: PetProfile, records: FeedingRecord[]): Promise<FeedingAdvice> {

const last24hRecords = records.filter(r => 
  Date.now() - r.timestamp < 24  60  60 * 1000
);

const totalAmount = last24hRecords.reduce((sum, r) => sum + r.amount, 0);
const isOverfed = totalAmount > pet.dailyFoodRequirement * 1.2;
const isUnderfed = totalAmount < pet.dailyFoodRequirement * 0.8;

const lastFeedingTime = last24hRecords.length > 0 

Math.max(…last24hRecords.map(r => r.timestamp))

0;

const hoursSinceLastFeeding = (Date.now() - lastFeedingTime) / (60  60  1000);
const isDueForFeeding = hoursSinceLastFeeding > pet.feedingInterval;

return {
  shouldFeed: isDueForFeeding || isUnderfed,
  suggestedAmount: this.calculateSuggestedAmount(pet, records),
  warning: isOverfed ? '可能喂食过量' : isUnderfed ? '可能喂食不足' : '',
  nextSuggestedTime: Date.now() + pet.feedingInterval  60  60 * 1000
};

private calculateSuggestedAmount(pet: PetProfile, records: FeedingRecord[]): number {

const last3DaysRecords = records.filter(r => 
  Date.now() - r.timestamp < 3  24  60  60  1000
);

if (last3DaysRecords.length === 0) {
  return pet.dailyFoodRequirement / (24 / pet.feedingInterval);

const avgAmount = last3DaysRecords.reduce((sum, r) => sum + r.amount, 0) /

  last3DaysRecords.length;

// 根据体重调整
const weightFactor = pet.weight / pet.idealWeight;
return avgAmount * (weightFactor > 1 ? 0.95 : weightFactor < 1 ? 1.05 : 1);

}

export const feedingAdviceService = FeedingAdviceService.getInstance();

三、主界面实现
声音监测界面

// PetSoundMonitorView.ets
@Component
struct PetSoundMonitorView {
@State isMonitoring: boolean = false;
@State lastSoundResult: PetSoundResult | null = null;
@State currentPet: PetProfile | null = null;

aboutToAppear() {
this.loadCurrentPet();
build() {

Column() {
  if (this.currentPet) {
    Text(正在监测: ${this.currentPet.name})
      .fontSize(20)
      .margin({ top: 16 })
    
    // 宠物图片
    Image(this.currentPet.imageUrl || 'resources/pet_placeholder.png')
      .width(120)
      .height(120)
      .borderRadius(60)
      .margin({ top: 16 })
    
    // 监测状态
    if (this.isMonitoring) {
      LoadingProgress()
        .width(50)
        .height(50)
        .margin({ top: 16 })
      
      Text('正在监听宠物声音...')
        .fontSize(16)
        .margin({ top: 8 })

else {

      Button('开始监听')
        .onClick(() => this.startMonitoring())
        .margin({ top: 16 })

// 上次识别结果

    if (this.lastSoundResult) {
      Column() {
        Text(识别结果: ${this.lastSoundResult.soundType})
          .fontSize(16)
          .margin({ top: 24 })
        
        Text(状态: ${this.lastSoundResult.isHungry ? '可能饥饿' : '正常'})
          .fontSize(16)
          .fontColor(this.lastSoundResult.isHungry ? '#FF5722' : '#4CAF50')
          .margin({ top: 8 })
        
        Text(置信度: ${(this.lastSoundResult.confidence * 100).toFixed(1)}%)
          .fontSize(14)
          .margin({ top: 8 })
        
        if (this.lastSoundResult.isHungry) {
          Button('立即喂食')
            .onClick(() => this.feedNow())
            .margin({ top: 16 })

}

} else {

    Text('请先添加宠物')
      .fontSize(16)
      .margin({ top: 32 })

}

.width('100%')
.height('100%')
.justifyContent(FlexAlign.Center)

private async loadCurrentPet(): Promise<void> {

// 简化示例,实际应用中可能有多个宠物选择
const pets = await petSyncService.getPetProfile('default_pet');
this.currentPet = pets;

private async startMonitoring(): Promise<void> {

this.isMonitoring = true;

await petAudioService.startRecording(async (audioData) => {
  try {
    this.lastSoundResult = await petSoundService.recognizePetSound(audioData);
    
    if (this.lastSoundResult.isHungry && this.currentPet) {
      EventBus.emit('petHungry', {
        pet: this.currentPet,
        soundResult: this.lastSoundResult
      });

} catch (err) {

    console.error('识别失败:', err);

finally {

    this.isMonitoring = false;

});

private async feedNow(): Promise<void> {

if (!this.currentPet) return;

const advice = await feedingAdviceService.getFeedingAdvice(
  this.currentPet,
  await petSyncService.getFeedingRecords(this.currentPet.id)
);

const record: FeedingRecord = {
  id: generateId(),
  petId: this.currentPet.id,
  amount: advice.suggestedAmount,
  timestamp: Date.now(),
  isAuto: false
};

await petSyncService.syncFeedingRecord(record);
EventBus.emit('feedingStarted', record);

}

function generateId(): string {
return Math.random().toString(36).substring(2) + Date.now().toString(36);

喂食记录界面

// FeedingHistoryView.ets
@Component
struct FeedingHistoryView {
@State records: FeedingRecord[] = [];
@State currentPet: PetProfile | null = null;
@State dailySummary: DailySummary = { totalAmount: 0, count: 0 };

aboutToAppear() {
this.loadCurrentPet();
EventBus.on(‘feedingRecordUpdated’, () => this.loadRecords());
build() {

Column() {
  if (this.currentPet) {
    Text(喂食记录: ${this.currentPet.name})
      .fontSize(20)
      .margin({ top: 16 })
    
    // 今日喂食统计
    Row() {
      Column() {
        Text('今日喂食')
          .fontSize(16)
        Text(${this.dailySummary.count}次)
          .fontSize(20)

.margin(8)

      Column() {
        Text('总食量')
          .fontSize(16)
        Text({this.dailySummary.totalAmount.toFixed(1)}{this.currentPet.foodUnit})
          .fontSize(20)

.margin(8)

.justifyContent(FlexAlign.SpaceAround)

    .margin({ top: 16 })
    
    // 记录列表
    if (this.records.length === 0) {
      Text('暂无喂食记录')
        .fontSize(16)
        .margin({ top: 32 })

else {

      List({ space: 10 }) {
        ForEach(this.records, (record) => {
          ListItem() {
            FeedingRecordItem({ record, unit: this.currentPet.foodUnit })

})

.layoutWeight(1)

}

}

private async loadCurrentPet(): Promise<void> {
this.currentPet = await petSyncService.getPetProfile(‘default_pet’);
await this.loadRecords();
private async loadRecords(): Promise<void> {

if (!this.currentPet) return;

this.records = await petSyncService.getFeedingRecords(this.currentPet.id);
this.records.sort((a, b) => b.timestamp - a.timestamp);

const today = new Date();
today.setHours(0, 0, 0, 0);

const todayRecords = this.records.filter(r => 
  new Date(r.timestamp) >= today
);

this.dailySummary = {
  count: todayRecords.length,
  totalAmount: todayRecords.reduce((sum, r) => sum + r.amount, 0)
};

}

@Component
struct FeedingRecordItem {
private record: FeedingRecord;
private unit: string;

build() {
Row() {
Column() {
Text(formatTime(this.record.timestamp))
.fontSize(16)

    Text(record.isAuto ? '自动喂食' : '手动喂食')
      .fontSize(12)
      .fontColor('#666666')
      .margin({ top: 4 })

.layoutWeight(1)

  Text({this.record.amount.toFixed(1)}{this.unit})
    .fontSize(18)

.padding(12)

}

function formatTime(timestamp: number): string {
const date = new Date(timestamp);
return {date.getHours()}:{date.getMinutes().toString().padStart(2, ‘0’)};

宠物健康报告界面

// PetHealthReportView.ets
@Component
struct PetHealthReportView {
@State currentPet: PetProfile | null = null;
@State healthData: HealthData = { feedingTrend: [], weightTrend: [] };
@State healthAdvice: string[] = [];

aboutToAppear() {
this.loadCurrentPet();
build() {

Column() {
  if (this.currentPet) {
    Text(${this.currentPet.name}的健康报告)
      .fontSize(20)
      .margin({ top: 16 })
    
    // 体重趋势
    Text('体重趋势')
      .fontSize(18)
      .margin({ top: 24 })
    
    if (this.healthData.weightTrend.length > 0) {
      // 简化的趋势图
      Row() {
        ForEach(this.healthData.weightTrend, (data) => {
          Column() {
            Text('')
              .width(20)
              .height(data.weight / this.currentPet.idealWeight * 50)
              .backgroundColor(data.weight > this.currentPet.idealWeight ? '#FF5722' : '#4CAF50')
            
            Text(formatDate(data.date))
              .fontSize(10)
              .margin({ top: 4 })

.margin({ right: 8 })

        })

.height(80)

      .margin({ top: 8 })

else {

      Text('暂无体重记录')
        .fontSize(14)
        .margin({ top: 8 })

// 喂食趋势

    Text('喂食趋势')
      .fontSize(18)
      .margin({ top: 24 })
    
    if (this.healthData.feedingTrend.length > 0) {
      // 简化的趋势图
      Row() {
        ForEach(this.healthData.feedingTrend, (data) => {
          Column() {
            Text('')
              .width(20)
              .height(data.amount / this.currentPet.dailyFoodRequirement * 30)
              .backgroundColor(data.amount > this.currentPet.dailyFoodRequirement ? '#FF5722' : '#4CAF50')
            
            Text(formatDate(data.date))
              .fontSize(10)
              .margin({ top: 4 })

.margin({ right: 8 })

        })

.height(60)

      .margin({ top: 8 })

else {

      Text('暂无喂食记录')
        .fontSize(14)
        .margin({ top: 8 })

// 健康建议

    Text('健康建议')
      .fontSize(18)
      .margin({ top: 24 })
    
    if (this.healthAdvice.length > 0) {
      Column() {
        ForEach(this.healthAdvice, (advice) => {
          Text(• ${advice})
            .fontSize(14)
            .margin({ top: 8 })
        })

} else {

      Text('暂无建议')
        .fontSize(14)
        .margin({ top: 8 })

}

.padding(16)

private async loadCurrentPet(): Promise<void> {

this.currentPet = await petSyncService.getPetProfile('default_pet');
if (this.currentPet) {
  await this.loadHealthData();
  this.generateHealthAdvice();

}

private async loadHealthData(): Promise<void> {
if (!this.currentPet) return;

const records = await petSyncService.getFeedingRecords(this.currentPet.id);
const now = new Date();

// 过去30天的喂食数据
this.healthData.feedingTrend = [];
for (let i = 29; i >= 0; i--) {
  const date = new Date(now);
  date.setDate(date.getDate() - i);
  date.setHours(0, 0, 0, 0);
  
  const nextDay = new Date(date);
  nextDay.setDate(nextDay.getDate() + 1);
  
  const dayRecords = records.filter(r => 
    r.timestamp >= date.getTime() && r.timestamp < nextDay.getTime()
  );
  
  this.healthData.feedingTrend.push({
    date: date.getTime(),
    amount: dayRecords.reduce((sum, r) => sum + r.amount, 0)
  });

// 模拟体重数据

if (this.currentPet.weightHistory) {
  this.healthData.weightTrend = this.currentPet.weightHistory;

}

private generateHealthAdvice(): void {
if (!this.currentPet) return;

this.healthAdvice = [];

// 根据体重给出建议
const weightRatio = this.currentPet.weight / this.currentPet.idealWeight;
if (weightRatio > 1.1) {
  this.healthAdvice.push('宠物可能超重,建议减少10%的喂食量并增加运动');

else if (weightRatio < 0.9) {

  this.healthAdvice.push('宠物可能偏瘦,建议增加10%的喂食量或咨询兽医');

// 根据喂食规律给出建议

const feedingTimes = this.healthData.feedingTrend.filter(d => d.amount > 0).length;
if (feedingTimes < 5) {
  this.healthAdvice.push(过去30天有${30 - feedingTimes}天没有喂食记录,请确保每日喂食);

}

function formatDate(timestamp: number): string {

const date = new Date(timestamp);
return {date.getMonth() + 1}/{date.getDate()};

四、高级功能实现
多设备协同喂食

// CollaborativeFeedingService.ets
class CollaborativeFeedingService {
private static instance: CollaborativeFeedingService;

private constructor() {}

public static getInstance(): CollaborativeFeedingService {
if (!CollaborativeFeedingService.instance) {
CollaborativeFeedingService.instance = new CollaborativeFeedingService();
return CollaborativeFeedingService.instance;

public async startFamilyFeeding(familyId: string): Promise<void> {

const devices = await deviceManager.getTrustedDevices();
await Promise.all(devices.map(device => 
  this.inviteDeviceToFamily(device.id, familyId)
));

private async inviteDeviceToFamily(deviceId: string, familyId: string): Promise<void> {

const ability = await featureAbility.startAbility({
  bundleName: 'com.example.petFeeder',
  abilityName: 'FamilyFeedingAbility',
  deviceId
});

await ability.call({
  method: 'joinFamilyFeeding',
  parameters: [familyId]
});

public async remoteFeedPet(deviceId: string, amount: number): Promise<void> {

const ability = await featureAbility.startAbility({
  bundleName: 'com.example.petFeeder',
  abilityName: 'RemoteFeedingAbility',
  deviceId
});

await ability.call({
  method: 'feedNow',
  parameters: [amount]
});

public async broadcastFeedingStatus(record: FeedingRecord): Promise<void> {

const devices = await deviceManager.getTrustedDevices();
await Promise.all(devices.map(device => 
  this.sendFeedingStatus(device.id, record)
));

private async sendFeedingStatus(deviceId: string, record: FeedingRecord): Promise<void> {

const ability = await featureAbility.startAbility({
  bundleName: 'com.example.petFeeder',
  abilityName: 'FeedingStatusAbility',
  deviceId
});

await ability.call({
  method: 'updateFeedingStatus',
  parameters: [record]
});

}

export const collaborativeFeedingService = CollaborativeFeedingService.getInstance();

智能喂食计划

// FeedingScheduleService.ets
import reminderAgent from ‘@ohos.reminderAgent’;

class FeedingScheduleService {
private static instance: FeedingScheduleService;

private constructor() {}

public static getInstance(): FeedingScheduleService {
if (!FeedingScheduleService.instance) {
FeedingScheduleService.instance = new FeedingScheduleService();
return FeedingScheduleService.instance;

public async scheduleRegularFeeding(pet: PetProfile): Promise<void> {

// 取消现有提醒
await this.cancelAllReminders();

// 根据宠物类型和年龄设置喂食时间
const feedingTimes = this.getFeedingTimesForPet(pet);

// 设置提醒
for (const time of feedingTimes) {
  const [hours, minutes] = time.split(':').map(Number);
  const reminderTime = new Date();
  reminderTime.setHours(hours, minutes, 0, 0);
  
  const reminderRequest: reminderAgent.ReminderRequest = {
    reminderType: reminderAgent.ReminderType.REMINDER_TYPE_TIMER,
    actionButton: [{ title: '已喂食' }, { title: '稍后提醒' }],
    wantAgent: {
      pkgName: 'com.example.petFeeder',
      abilityName: 'FeedingReminderAbility'
    },
    ringDuration: 60,
    snoozeTimes: 2,
    triggerTime: reminderTime.getTime(),
    repeatInterval: 24  60  60 * 1000, // 每天重复
    title: ${pet.name}的喂食时间,
    content: 该给${pet.name}喂食了,
    expiredContent: "喂食提醒已过期"
  };
  
  await reminderAgent.publishReminder(reminderRequest);

}

private getFeedingTimesForPet(pet: PetProfile): string[] {
// 根据宠物类型和年龄返回建议喂食时间
if (pet.type === ‘dog’) {
return pet.age < 1 ? [‘08:00’, ‘12:00’, ‘18:00’] : [‘08:00’, ‘18:00’];
else if (pet.type === ‘cat’) {

  return ['07:00', '19:00'];

return [‘12:00’]; // 默认中午喂食

public async cancelAllReminders(): Promise<void> {

const reminders = await reminderAgent.getValidReminders();
await Promise.all(reminders.map(rem => 
  reminderAgent.cancelReminder(rem.id)
));

}

export const feedingScheduleService = FeedingScheduleService.getInstance();

宠物健康监测

// PetHealthMonitorService.ets
class PetHealthMonitorService {
private static instance: PetHealthMonitorService;

private constructor() {}

public static getInstance(): PetHealthMonitorService {
if (!PetHealthMonitorService.instance) {
PetHealthMonitorService.instance = new PetHealthMonitorService();
return PetHealthMonitorService.instance;

public async analyzeHealthStatus(pet: PetProfile, records: FeedingRecord[]): Promise<HealthStatus> {

const lastWeekRecords = records.filter(r => 
  Date.now() - r.timestamp < 7  24  60  60  1000
);

const dailyAverage = lastWeekRecords.reduce((sum, r) => sum + r.amount, 0) / 
  Math.max(1, lastWeekRecords.length / (24 / pet.feedingInterval));

const weightStatus = pet.weight > pet.idealWeight * 1.15 ? 'overweight' :
  pet.weight < pet.idealWeight * 0.85 ? 'underweight' : 'normal';

const feedingConsistency = this.calculateFeedingConsistency(lastWeekRecords);

return {
  weightStatus,
  feedingConsistency,
  suggestedAction: this.getSuggestedAction(weightStatus, dailyAverage, pet.dailyFoodRequirement)
};

private calculateFeedingConsistency(records: FeedingRecord[]): number {

if (records.length === 0) return 0;

const timeStamps = records.map(r => r.timestamp).sort();
const intervals = [];

for (let i = 1; i < timeStamps.length; i++) {
  intervals.push((timeStamps[i] - timeStamps[i - 1]) / (60  60  1000));

const avgInterval = intervals.reduce((sum, val) => sum + val, 0) / intervals.length;

const variance = intervals.reduce((sum, val) => sum + Math.pow(val - avgInterval, 2), 0) / intervals.length;

return Math.max(0, 1 - variance / 4); // 0-1之间,1表示最规律

private getSuggestedAction(weightStatus: string, dailyAverage: number, requirement: number): string {

switch (weightStatus) {
  case 'overweight':
    return 当前每日平均喂食量{dailyAverage.toFixed(1)}g,建议减少至{(requirement * 0.9).toFixed(1)}g;
  case 'underweight':
    return 当前每日平均喂食量{dailyAverage.toFixed(1)}g,建议增加至{(requirement * 1.1).toFixed(1)}g;
  default:
    return dailyAverage > requirement * 1.1 

当前每日平均喂食量{dailyAverage.toFixed(1)}g,略高于建议量{requirement.toFixed(1)}g

喂食量合适,继续保持;

}

export const healthMonitorService = PetHealthMonitorService.getInstance();

五、总结

本智能宠物喂食提醒系统实现了以下核心价值:
智能识别:通过声音识别判断宠物饥饿状态

科学喂养:根据宠物种类、年龄和体重提供个性化喂食建议

多设备协同:家庭成员可共享喂食记录和远程控制

健康监测:跟踪喂食规律和体重变化,预防健康问题

习惯养成:定时提醒帮助建立规律的喂食习惯

扩展方向:
集成智能喂食器硬件控制

增加宠物活动量监测

开发宠物社交分享功能

接入兽医在线咨询服务

注意事项:
需要申请ohos.permission.MICROPHONE权限

声音识别准确率受环境噪音影响

喂食建议仅供参考,具体请咨询专业兽医

多设备协同需保持网络连接

首次使用需设置宠物基本信息

©著作权归作者所有,如需转载,请注明出处,否则将追究法律责任
收藏
回复
举报
回复
    相关推荐