Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kokeiro001/852f01d342ebd14ccc1e8e35daa0af3c to your computer and use it in GitHub Desktop.
Save kokeiro001/852f01d342ebd14ccc1e8e35daa0af3c to your computer and use it in GitHub Desktop.
GoogleCloudSpeechを使って、音声ファイルをテキストに変換する機能を使ってみる
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Remove="voice\**" />
<EmbeddedResource Remove="voice\**" />
<None Remove="voice\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Google.Cloud.Speech.V1" Version="1.0.0-beta09" />
</ItemGroup>
</Project>
using Google.Cloud.Speech.V1;
using System;
using System.Linq;
using System.Diagnostics;
namespace GoogleCloudSpeechSandbox.ConsoleApp
{
class Program
{
public static void Main(string[] args)
{
var speech = SpeechClient.Create();
var response = speech.Recognize(new RecognitionConfig()
{
Encoding = RecognitionConfig.Types.AudioEncoding.Linear16,
LanguageCode = "ja-JP",
},
RecognitionAudio.FromFile("voice/voice.wav"));
foreach (var result in response.Results)
{
var array = result.Alternatives.ToArray();
foreach (var alternative in array)
{
Debug.WriteLine(alternative.Transcript);
Console.WriteLine(alternative.Transcript);
}
}
Console.WriteLine("Finish.");
Console.ReadKey();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment