gpt4 book ai didi

c# - 在 Xamarin.Forms 中录制语音后如何保存音频文件

转载 作者:行者123 更新时间:2023-12-03 00:13:01 26 4
gpt4 key购买 nike

我想知道如何以 Xamarin 形式保存音频文件。我可以使用 Xamarin.Essentials 获取保存到 AppDataDirectory 的位置:

var mainDir = FileSystem.AppDataDirectory;

但我不确定如何在使用 NateRickard AudioRecorder 插件录制后将其保存在代码中:
var recordTask = await recorder.StartRecording();
var audioFile = await recordTastk; //audioFile is of string datatype

它与在 C# 中保存/创建任何二进制文件相同吗?说它与保存图像文件相同?此外,我是否需要使用依赖注入(inject)来使用特定于平台的代码来保存它,或者我只能设法从 PCL 代码中做到这一点?

最佳答案

docs明确讨论这一点:

Accessing the Recorded File

There are multiple ways to access the recorded audio file path:

  • The Task-based API will return the file path when the task completes. The Task can be awaited or use standard Task continuation APIs.
  • The Event-based API will return the full path to the recorded audio file in the audioFile parameter of the AudioInputReceived event
    handler.
  • The GetAudioFilePath () method on the AudioRecorderService class will return the recorded audio file path.

These will all return null in the case that no audio has been recorded yet or no audio was recorded/detected in the last recording session.

Once you have the path to the recorded audio file, you can use standard file operations (for native/.NET Standard) and/or a cross platform file system abstraction like PCLStorage to get a stream to the file data.

关于c# - 在 Xamarin.Forms 中录制语音后如何保存音频文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53232889/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com