php - 在 golang 中读取 *.wav 文件

标签 php go wav

我使用 file_get_contents 在 PHP 中读取 WAV 文件,我想使用包 github.com/mjibson/go-dsp/wav对于 Go 中的相同任务。但是没有关于这个包的任何简单示例。我是 Go 的新手,不了解它。有没有人指导我或建议其他方法?

PHP 代码:

$wsdl = 'http://myApi.asmx?WSDL';
$client = new SoapClient($wsdl));
$data = file_get_contents(public_path() . "/forTest/record.wav");
$param = array(
  'userName' => '***',
  'password' => '***',
  'file' => $data);

$res = $client->UploadMessage($param);

最佳答案

看起来你不需要使用这个包github.com/mjibson/go-dsp/wavfile_get_contents 函数是将文件内容读入字符串的首选方法。

在 Go 中,你可以这样做:

package main

import (
    "fmt"
    "io/ioutil"
)

func public_path() string {
    return "/public/path/"
}

func main() {
    dat, err := ioutil.ReadFile(public_path() + "/forTest/record.wav")
    if err != nil {
        fmt.Println(err)
    }
    fmt.Print(string(dat))
}

https://play.golang.org/p/l9R0940iK50

关于php - 在 golang 中读取 *.wav 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53022186/

相关文章:

php - 将 Doctrine 与 View 一起使用 - 生成了无效的 'id' 字段

go - 如何将带参数的函数句柄传递给 Go 中的另一个函数?

go - 为什么 go benchmark 在不同地方用相同的代码显示不同的结果?

c - 我的 10 线音频播放器

mp3 - 如何使用 sox 将 wav 文件转换为 mp3 格式?

php - Yii2 - beforeAction 期间的返回响应

php - PHPUnit生成clover.xml时定义相对路径?

php - 将 SQL 输出存储在数组中

while-loop - Golang 保持功能活跃

android - 如何使用 AudioCodec 重新采样音频?