You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何访问Photon Recorder组件?命名空间引用问题求助

解决Photon Recorder组件引用问题及按键说话实现

一、修复组件引用失败问题

你之前用的命名空间不对,Photon Voice 2的Recorder组件实际位于Photon.Voice.Unity命名空间,替换成这个就能正常引用:

using Photon.Voice.Unity;

之后直接用Recorder类即可,不用再试那些错误的类名。另外要确认你安装的是Photon Voice 2(当前主流稳定版本),旧版Voice 1的组件结构和命名空间差异很大,建议直接升级到最新版。

二、按键说话功能实现代码示例

先给目标GameObject添加Recorder组件,再挂载以下脚本:

using UnityEngine;
using Photon.Voice.Unity;

public class PushToTalk : MonoBehaviour
{
    private Recorder _voiceRecorder;

    void Start()
    {
        _voiceRecorder = GetComponent<Recorder>();
        // 默认关闭录音
        _voiceRecorder.Recording = false;
    }

    void Update()
    {
        // 按住左Alt键触发说话(可替换为你需要的按键,比如KeyCode.Space、KeyCode.LeftControl)
        _voiceRecorder.Recording = Input.GetKey(KeyCode.LeftAlt);
    }
}

三、额外排查要点

  • 确认Photon Voice包完整导入:在Unity Package Manager里检查Photon Voice 2是否安装成功,无文件缺失。
  • 配置Recorder组件:Inspector面板中,确保Recorder的Audio Source设为麦克风输入,Transmit Enabled处于勾选状态。
  • 权限检查:移动端要提前申请麦克风权限,PC端确保Unity项目有麦克风访问权限。

内容的提问来源于stack exchange,提问作者Jerry

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.08 20:50:27