flutter webRTC 如何发送音频文件 Uint8List

问题描述 投票:0回答:0

我使用 webRTC 连接点对点,但是当我使用 TTS 并获取有关 TTS 数据的 uint8list 数据时,我尝试发送或写入有关来自 TTS 的语音的其他点。 首先,我尝试在 _localStream!.getAudioTracks()[0] 中写入,但找不到方法。 其次我尝试制作音轨并添加到 RTCPeerConnection 但无法找到从 Uint 8 List 制作 MediaStreamTrack 或 MediaStream 的方法

有什么办法吗?

  late final WebSocket socket;
  final _localRenderer = RTCVideoRenderer();
  RTCVideoRenderer get localRenderer => _localRenderer;
  final _remoteRenderer = RTCVideoRenderer();
  RTCVideoRenderer get remoteRenderer => _remoteRenderer;

  MediaStream? _localStream;
  MediaStream? get localStream => _localStream;

  RTCPeerConnection? _pc;

  Future init({required String clientIdUri, required String channelARN}) async {
    getCredentials().then((value) {
      clientIdUri = value.userIdentityId!.split(':').last;
      AwsCognito()
          .sign(
        uri: Uri.parse(
            "wss://<uri>"),
        accessKey: value.accessKeyId!,
        secretKey: value.secretAccessKey!,
        sessionToken: value.sessionToken!,
        wssUri: Uri.parse(
            "wss://<uri>),
        region: "ap-northeast-2",
      )
          .then((valueSign) {
        service!
            .getIceServerConfig(
          channelARN:
              "arn:aws:kinesisvideo:ap-northeast-2:<uri>,
        )
            .then((value) async {
          if (value.iceServerList != null) {
            await _localRenderer.initialize();
            await _remoteRenderer.initialize();

            await joinRoom(value.iceServerList!);
            await connectSocket(wssUri: valueSign, clientId: clientIdUri);
          }
        });
      });
    });

    notifyListeners();
  }

// this is 
  Future<void> sendTtsData(Uint8List data) async {
    
    // MediaStream inboundStream = MediaStream();
    // videoElem.srcObject = inboundStream;

    // _pc!._localStream!.addTrack(MediaStreamTrack());
    // // _localStream!.removeTrack(MediaStreamTrack());
    //
    // // for (MediaStreamTrack track in _localStream!.getTracks()) {
    // //   RTCRtpSender sender = await _pc!.addTrack(track, _localStream!);

    if (_localStream!.getAudioTracks().isNotEmpty) {
      // MediaStreamTrack audioTtsTrack = _localStream!.addTrack(audioTtsTrack);
      MediaStreamTrack ttsStream = Buffer.fromBuffer(data.buffer);
      _localStream!.getAudioTracks().add(DataT);


      // void createMediaStream() {
      //   if (_audioData != null) {
      //     _mediaStream = MediaStream.fromBytes('audio/mpeg', _audioData);
      //   }
      // }

      _pc!.addStream(stream)

      // _pc!.createDtmfSender(ttsStream);
      // _pc!.addStream().
    }

    // sendData(socket!, data);
    notifyListeners();
  }

flutter webrtc
© www.soinside.com 2019 - 2024. All rights reserved.