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

标签 c# file audio xamarin.forms save

我想知道如何以 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/

相关文章:

c# - 使用其 x :Name as a parameter in a method in the code-behind 绑定(bind)按钮 IsEnabled/Visibility 属性

c# - 所查看的 MSMQ 消息的 message.ID 不知何故丢失

c# - 查找所有父类型(包括基类和接口(interface))

javascript - 在行号nodejs处插入字符串

java - 是否有用于监听音频命令的 Kotlin 或 Java 库? (想要在 child 大喊 'TRICK OR TREAT' 时触发万圣节显示)

algorithm - 检测声音文件中的重复

c# - 在 .Net 4.0 中使用 poor mans async/await 构造实现异步超时

java - 配置扫描本地文件系统的 TreeView 以仅包含具有文件类型的文件夹

javascript - 关于简单拖放 Div 区域的警报

javascript - onmousedown 播放声音