How to save the whole conversation?


I'm using Photon Voice and want to record every user's voice in the room on one client's end, and I found this documenton the official website. But I can't find any of them in any namespace or class, and WebRtcAudioDsp.cs doesn't exist. So my question is how to use it?

For reference, the Unity version I'm using is 2019.4.11, and Photon Voice is 2.22.2.

Thanks in advance!


  • Hi @Danhua,

    Check out these two utility scripts available in the package:

    - "Assets\Photon\PhotonVoice\Code\UtilityScripts\SaveIncomingStreamToFile.cs": attach it to the same GameObject as the VoiceConnection or PhotonVoiceNetwork component.
    - "Assets\Photon\PhotonVoice\Code\UtilityScripts\SaveOutgoingStreamToFile.cs": attach it to the same GameObject as the Recorder component.

    Files will be saved under Application.persistentDataPath.

    They follow the same logic as what's explained in the documentation you have linked.

    The WebRtcAudioDsp class is available in the Photon.Voice.Unity namespace.
    The file is located at this path: "Assets\Photon\PhotonVoice\Code\WebRtcAudioDsp.cs".
  • Found it! Thanks for your help!
  • Hi there! After trying out the code, I have the following questions:

    1. I'm following this settings for my voice manager object. Namely, PhotonVoiceNetwork and Recorder are both attached to the voice manager, so I attach SaveIncomingStreamToFile.cs and SaveOutgoingStreamToFile.cs to the same gameobject. But when I run the project myself (only one person in the room), I found two recorded .wav files. One of them is correct, yet the other is always blank (44 bytes).
    My project has a lobby and a room. Each player enters the lobby first, and then jump into the room.
    So I tried turning on and off the toggle "Don't Destroy on Load" on Photon Voice Network component, but it doesn't make any difference. How should I fix this issue?

    2. How do I get the PlayerId for each player's voice, except modifying the "SaveOutgoingStreamToFIle.cs" script directly?
  • 1. I'm not sure if the blank file is "out_*.wav" or "in_*.wav". If it's "out_*.wav" then this probably means that your Recorder has AutoStart and it started recording for a short period of time then somehow it got restarted probably because something has changed, this could be due to the PhotonVoiceView.SetupRecorder after setting Recorder.UserData = photonViewId. What you could do is to disable Recorder.AutoStart and manually call Recorder.StartRecording when ready (photonVoiceView.IsRecorder).
    2. Yes you can make your own custom class inspired from that script and get actor number from PhotonVoiceNetwork.Instance.Client.LocalPlayer.ActorNumber. You could also add more metadata if you want.
  • Thanks for your response! Sorry that I didn't have time to fix the issues I mentioned above today, but I got another one which is confusing to me: You mentioned that I could use PhotonVoiceNetwork.Instance.Client.LocalPlayer.ActorNumber to identify each user, does this have the same value as PhotonView.Owner.ActorNumber for the local player? I'm using PhotonView.Owner.ActorNumber and PhotonView.Owner.Nickname to name the output audio files, so I want to know what does remoteVoiceLink.VoiceId and remoteVoiceLink.PlayerId mean in the script "SaveIncomingStreamToFile.cs"? My guess is that remoteVoiceLink.VoiceId is the same as PhotonView.Owner.ActorNumber, and remoteVoiceLink.PlayerID is the order of joining the room, like the first or the second to enter the room, but I'm uncertain if my understanding is correct.
  • If you are using the default recommended PUN integration based on PhotonVoiceView then yes
    PhotonVoiceNetwork.Instance.Client.LocalPlayer.ActorNumber is the same as photonView.Owner.ActorNumber locally (photonView.Owner.IsLocal).

    RemoteVoiceLink.PlayerId is the same as actor number and not the VoiceId.
    The VoiceId is a number assigned to the voice stream to identify it, since you could use more than one Recorder to have more than one outgoing streams (up to 255).
    In most cases, you don't need to touch this.
  • Thank you very much for the explanation!
Sign In or Register to comment.