Commit 14571fd2 authored by 藤森雅人's avatar 藤森雅人
Browse files

Initial commit

parents
[sp2txt](ルートフォルダ)ファイル構成
2019年7月26日 藤森雅人
[cpprestsdk_static_tester]
 Visual Studioのソリューションフォルダ
 プログラム本体に相当します。
_README.txt
 このテキスト。
call_api.sh / call_api_log.sh
 吉田さんが書いたシェルスクリプト。
 curlでSpeech to TextのAPIを叩いている。
 今回のプログラムはおおむねこれを模倣するものである。
baseball.wav
 テストデータにする野球実況中継の音声。約55分。
 ステレオ、サンプリングレート48,000。
baseball_01.wav ... baseball_12.wav
 baseball.wavを、音声の先頭と終端で会話が途切れないように
 約5分刻みで12分割したもの。
baseball_01.opus ... baseball_12.opus
 baseball_01.wav ... baseball_12.wavをプログラム中で
 opus形式音声に変換してファイル出力したもの。
 フリーソフトではVLCプレイヤーが再生に便利。
baseball_01.txt ... baseball_12.txt
 baseball_01.wav ... baseball_12.wavの書き起こし結果を
 取得したものをプログラム中でファイル出力したもの。
 JSON形式。
afternoon9_5sec.wav / afternoon12sec.wav / afternoon_narra.wav
 テストデータ音声。内容はラジオ取材らしい。
 順に9.5秒、12秒、約1分。
 変換可能な音声の再生時間に上限のあるアカウントで
 APIを叩く場合はこれを使います。
 宮澤さんのアカウントは無制限だが吉田さんのは月100分までなので、
 吉田さんのを使う場合はこの短い音声を使うのを推奨します。
\ No newline at end of file
curl -X POST -u "9427bcd0-6410-4ef7-b195-9e5b93ae9542":"xCPGobm6tk2X" --header "Content-Type: audio/wav" --data-binary @afternoon_narra.wav "https://stream.watsonplatform.net/speech-to-text/api/v1/recognize?model=ja-JP_BroadbandModel&timestamps=true&speaker_labels=true" > afternoon_narra00.spt
curl --trace-ascii logoutfile -X POST -u "9427bcd0-6410-4ef7-b195-9e5b93ae9542":"xCPGobm6tk2X" --header "Content-Type: audio/wav" --data-binary @afternoon_narra.wav "https://stream.watsonplatform.net/speech-to-text/api/v1/recognize?model=ja-JP_BroadbandModel&timestamps=true&speaker_labels=true"
curl --trace-ascii logoutfile -X POST -u "9427bcd0-6410-4ef7-b195-9e5b93ae9542":"xCPGobm6tk2X" --header "Content-Type: audio/wav" --data-binary @afternoon_narra.wav "https://stream.watsonplatform.net/speech-to-text/api/v1/recognize?model=ja-JP_BroadbandModel&timestamps=true&speaker_labels=true"

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27130.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MFCApplication2", "MFCApplication2\MFCApplication2.vcxproj", "{83F8DD07-C00C-41DA-9F31-68C3C36CCE67}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{83F8DD07-C00C-41DA-9F31-68C3C36CCE67}.Debug|x64.ActiveCfg = Debug|x64
{83F8DD07-C00C-41DA-9F31-68C3C36CCE67}.Debug|x64.Build.0 = Debug|x64
{83F8DD07-C00C-41DA-9F31-68C3C36CCE67}.Debug|x86.ActiveCfg = Debug|Win32
{83F8DD07-C00C-41DA-9F31-68C3C36CCE67}.Debug|x86.Build.0 = Debug|Win32
{83F8DD07-C00C-41DA-9F31-68C3C36CCE67}.Release|x64.ActiveCfg = Release|x64
{83F8DD07-C00C-41DA-9F31-68C3C36CCE67}.Release|x64.Build.0 = Release|x64
{83F8DD07-C00C-41DA-9F31-68C3C36CCE67}.Release|x86.ActiveCfg = Release|Win32
{83F8DD07-C00C-41DA-9F31-68C3C36CCE67}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2CC2CAD0-7BA6-41D7-9737-238D6F5B4602}
EndGlobalSection
EndGlobal
B// Microsoft Visual C++ で生成されたリソース スクリプトです。
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>15.0</VCProjectVersion>
<ProjectGuid>{83F8DD07-C00C-41DA-9F31-68C3C36CCE67}</ProjectGuid>
<Keyword>MFCProj</Keyword>
<RootNamespace>MFCApplication2</RootNamespace>
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
<UseOfMfc>Static</UseOfMfc>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<UseOfMfc>Dynamic</UseOfMfc>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
<UseOfMfc>Static</UseOfMfc>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<UseOfMfc>Dynamic</UseOfMfc>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<LibraryPath>$(LibraryPath);</LibraryPath>
<Linkage-curl>static</Linkage-curl>
<Linkage-openssl>static</Linkage-openssl>
<Linkage-zlib>static</Linkage-zlib>
<Linkage-libssh2>static</Linkage-libssh2>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<LibraryPath>C:\curl\builds\libcurl-vc-x86-release-static-ipv6-sspi-winssl\lib;..\vcpkg\debug\lib;$(LibraryPath)</LibraryPath>
<IncludePath>C:\curl\builds\libcurl-vc-x86-release-static-ipv6-sspi-winssl\include;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;_NO_ASYNCRTIMP;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\libopus\include;..\vcpkg\include;..\libopusfile\include;..\libopusenc\include;..\libogg\include;..\libogg\include\ogg;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions>/await %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<AdditionalDependencies>libeay32.lib;ssleay32.lib;winhttp.lib;bcrypt.lib;crypt32.lib;cpprest_2_10d.lib;zlibd.lib;opusfile.lib;opusenc.lib</AdditionalDependencies>
<LinkTimeCodeGeneration>
</LinkTimeCodeGeneration>
<AdditionalLibraryDirectories>..\vcpkg\lib;..\libopus\lib;..\libopusfile\lib;..\libopusenc\lib;..\libogg\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<EntryPointSymbol>
</EntryPointSymbol>
</Link>
<Midl>
<MkTypLibCompatible>false</MkTypLibCompatible>
<ValidateAllParameters>true</ValidateAllParameters>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</Midl>
<ResourceCompile>
<Culture>0x0411</Culture>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_WINDOWS;_DEBUG;_NO_ASYNCRTIMP;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>C:\opus\src;C:\opus\include;C:\Users\mfujimori\dev\sp2txt\cpprestsdk_static_tester\vcpkg\lib;C:\Users\mfujimori\dev\sp2txt\cpprestsdk_static_tester\vcpkg\include;C:\Users\mfujimori\dev\sp2txt\cpprestsdk_static_tester\libcurl\include;C:\tools\boost;C:\Users\mfujimori\dev\sp2txt\cpprestsdk_static_tester\libopus\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions>-lcurl %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<AdditionalDependencies>libeay32.lib;ssleay32.lib;winhttp.lib;bcrypt.lib;crypt32.lib;cpprest_2_10d.lib;zlibd.lib;Ws2_32.lib;Wldap32.lib;Normaliz.lib;opus.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>C:\opus\win32\VS2015\Win32\ReleaseDLL_fixed\opus;C:\Users\mfujimori\dev\sp2txt\cpprestsdk_static_tester\libopus\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
<Midl>
<MkTypLibCompatible>false</MkTypLibCompatible>
<ValidateAllParameters>true</ValidateAllParameters>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</Midl>
<ResourceCompile>
<Culture>0x0411</Culture>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>C:\Users\mfujimori\dev\sp2txt\cpprestsdk_static_tester\MFCApplication2\opus;C:\Users\mfujimori\dev\sp2txt\cpprestsdk_static_tester\vcpkg\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalLibraryDirectories>C:\Users\mfujimori\dev\sp2txt\cpprestsdk_static_tester\vcpkg\lib;C:\Users\mfujimori\dev\sp2txt\cpprestsdk_static_tester\MFCApplication2\opus\lib\Release;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>opus.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Midl>
<MkTypLibCompatible>false</MkTypLibCompatible>
<ValidateAllParameters>true</ValidateAllParameters>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</Midl>
<ResourceCompile>
<Culture>0x0411</Culture>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_WINDOWS;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
<Midl>
<MkTypLibCompatible>false</MkTypLibCompatible>
<ValidateAllParameters>true</ValidateAllParameters>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</Midl>
<ResourceCompile>
<Culture>0x0411</Culture>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="MFCApplication2.h" />
<ClInclude Include="MFCApplication2Dlg.h" />
<ClInclude Include="opusenc_exec.h" />
<ClInclude Include="stdafx.h" />
<ClInclude Include="win32utf8.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="MFCApplication2.cpp" />
<ClCompile Include="MFCApplication2Dlg.cpp" />
<ClCompile Include="stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="win32utf8.cpp" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="MFCApplication2.rc" />
</ItemGroup>
<ItemGroup>
<None Include="res\MFCApplication2.rc2" />
</ItemGroup>
<ItemGroup>
<Image Include="res\MFCApplication2.ico" />
<Image Include="res\Toolbar.bmp" />
<Image Include="res\Toolbar256.bmp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets" />
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="ソース ファイル">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="ヘッダー ファイル">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="リソース ファイル">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="MFCApplication2.h">
<Filter>ヘッダー ファイル</Filter>
</ClInclude>
<ClInclude Include="MFCApplication2Dlg.h">
<Filter>ヘッダー ファイル</Filter>
</ClInclude>
<ClInclude Include="stdafx.h">
<Filter>ヘッダー ファイル</Filter>
</ClInclude>
<ClInclude Include="opusenc_exec.h">
<Filter>ヘッダー ファイル</Filter>
</ClInclude>
<ClInclude Include="win32utf8.h">
<Filter>ヘッダー ファイル</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="MFCApplication2.cpp">
<Filter>ソース ファイル</Filter>
</ClCompile>
<ClCompile Include="MFCApplication2Dlg.cpp">
<Filter>ソース ファイル</Filter>
</ClCompile>
<ClCompile Include="stdafx.cpp">
<Filter>ソース ファイル</Filter>
</ClCompile>
<ClCompile Include="win32utf8.cpp">
<Filter>ソース ファイル</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="MFCApplication2.rc">
<Filter>リソース ファイル</Filter>
</ResourceCompile>
</ItemGroup>
<ItemGroup>
<None Include="res\MFCApplication2.rc2">
<Filter>リソース ファイル</Filter>
</None>
</ItemGroup>
<ItemGroup>
<Image Include="res\MFCApplication2.ico">
<Filter>リソース ファイル</Filter>
</Image>
<Image Include="res\Toolbar.bmp">
<Filter>リソース ファイル</Filter>
</Image>
<Image Include="res\Toolbar256.bmp">
<Filter>リソース ファイル</Filter>
</Image>
</ItemGroup>
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ShowAllFiles>false</ShowAllFiles>
</PropertyGroup>
</Project>
\ No newline at end of file
[MFCApplication2]ファイル構成
2019年7月26日 藤森雅人
***.h
 ヘッダファイル。
***.cpp
 ソースコード。
その他
 プロジェクトの管理で用いられるファイル。
[Debug]
 圧縮する時はフォルダごと消しても支障がない。
[x64]
 ターゲットをx64に指定するとできる。
 今回はx86で作成しているので、
 圧縮する時はフォルダごと消しても支障がない。
\ No newline at end of file
This diff is collapsed.
#pragma once
#include <stdio.h>
#include "opusenc.h"
#include "os_types.h"
#if defined WIN32 || defined _WIN32
# include <windows.h> /*GetFileType()*/
# include <io.h> /*_get_osfhandle()*/
#endif
#ifdef ENABLE_NLS
# include <libintl.h>
# define _(X) gettext(X)
#else
# define _(X) (X)
# define textdomain(X)
# define bindtextdomain(X, Y)
#endif
#ifdef gettext_noop
# define N_(X) gettext_noop(X)
#else
# define N_(X) (X)
#endif
/* Macros for handling potentially large file offsets */
#if defined WIN32 || defined _WIN32
# define OFF_T __int64
/* On Windows, fseek() on pipes may return zero even though it doesn't seek. */
# if defined __MINGW32__ || defined __MINGW64__
# define FSEEK(s,o,w) (((GetFileType((HANDLE)_get_osfhandle(_fileno(s)))&~FILE_TYPE_REMOTE)==FILE_TYPE_DISK)?fseeko64((s),(o),(w)):1)
# define FTELL ftello64
# else
# define FSEEK(s,o,w) (((GetFileType((HANDLE)_get_osfhandle(_fileno(s)))&~FILE_TYPE_REMOTE)==FILE_TYPE_DISK)?_fseeki64((s),(o),(w)):1)
# define FTELL _ftelli64
# endif
#elif defined HAVE_FSEEKO
# define OFF_T off_t
# define FSEEK fseeko
# define FTELL ftello
#else
# define OFF_T long
# define FSEEK fseek
# define FTELL ftell
#endif
#define READ_SIZE 256
/* Macros to read header data */
#define READ_U32_LE(buf) \
(((unsigned int)(buf)[3]<<24)|((buf)[2]<<16)|((buf)[1]<<8)|((buf)[0]))
#define READ_U16_LE(buf) \
(((buf)[1]<<8)|((buf)[0]&0xff))
#define READ_U32_BE(buf) \
(((unsigned int)(buf)[0]<<24)|((buf)[1]<<16)|((buf)[2]<<8)|((buf)[3]))
#define READ_U16_BE(buf) \
(((buf)[0]<<8)|((buf)[1]&0xff))
typedef struct {
unsigned short format;
unsigned short channels;
unsigned int samplerate;
unsigned int bytespersec;
unsigned short align;
unsigned short samplesize;
unsigned int mask;
} wav_fmt;
#if 0
void splitpath(const char *path, char *drv, char *dir, char *name, char *ext) {
const char *end;
const char *p;
const char *s;
if (path[0] && path[1] == ':') {
if (drv) {
*drv++ = *path++;
*drv++ = *path++;
*drv = '\0';
}
}
else if (drv)
*drv = '\0';
for (end = path; *end && *end != ':';)
end++;
for (p = end; p > path && *--p != '\\' && *p != '/';)
if (*p == '.') {
end = p;
break;
}
if (ext)
for (s = end; (*ext = *s++);)
ext++;
for (p = end; p > path;)
if (*--p == '\\' || *p == '/') {
p++;
break;
}
if (name) {
for (s = p; s < end;)
*name++ = *s++;
*name = '\0';
}
if (dir) {
for (s = path; s < p;)
*dir++ = *s++;
*dir = '\0';
}
}
#endif
static void sanitize_fourcc(unsigned char *buf)
{
int i;
for (i = 0; i < 4; ++i)
if (buf[i] < ' ' || buf[i] > '~')
buf[i] = '?';
}
static int seek_forward(FILE *in, ogg_int64_t length)
{
ogg_int64_t remaining = length;
while (remaining > 0)
{
/* When OFF_T is 64 bits, only one seek is needed and the comparison
* will always be false. When OFF_T is not large enough, seek LONG_MAX
* bytes at a time (the maximum offset that basic fseek() can handle).
*/
OFF_T seekstep = (OFF_T)remaining;
if (seekstep != remaining)
seekstep = LONG_MAX;
if (FSEEK(in, seekstep, SEEK_CUR))
{
/* Failed to seek; do it by reading. */
unsigned char buf[1024];
do {
size_t readstep = remaining > 1024 ? 1024 : (size_t)remaining;
readstep = fread(buf, 1, readstep, in);
if (!readstep)
return 0; /* Couldn't read more, can't read file */
remaining -= readstep;
} while (remaining);
break;
}
remaining -= seekstep;
}
return 1;
}
static int find_wav_chunk(FILE *in, char *type, unsigned int *len)
{
unsigned char buf[8];
unsigned int chunklen;
while (1)
{
if (fread(buf, 1, 8, in) < 8) /* Suck down a chunk specifier */
return 0; /* EOF before reaching the appropriate chunk */
chunklen = READ_U32_LE(buf + 4);
if (memcmp(buf, type, 4))
{
sanitize_fourcc(buf);
fprintf(stderr, _("Skipping chunk of type \"%.4s\", length %u\n"),
buf, chunklen);
if (!seek_forward(in, (ogg_int64_t)chunklen + (chunklen & 1)))
return 0;
}
else
{
*len = chunklen;
return 1;
}
}
}
int convert(char *path) {
FILE *fin;
OggOpusEnc *enc;
OggOpusComments *comments;
wav_fmt format;
unsigned char buf[40];
unsigned int len;
int error;
char out_file[1024];
{
char *in_file = path;
char drive[3];
char dir[256];
char fname[256];
char ext[256];
splitpath(in_file, drive, dir, fname, ext);
if (memcmp(".wav", ext, strlen(ext)) == 0) {
sprintf_s(out_file, "%s%s%s.opus", drive, dir, fname);
}
}
ods(path);
ods(out_file);
fopen_s(&fin, path, "rb");
if (!fin) {
ods("[convert-fopen_s] error\n");
return 1;
}
// 音声のチャンネル、周波数の読み取り
//if (!find_wav_chunk(fin, "fmt ", &len))
//{
// ods("[find_wav_chunk] \"fmt \" failed.\n");
// return 1;
//}
//format.channels = READ_U16_LE(buf + 2);
//format.samplerate = READ_U32_LE(buf + 4);
//if (!find_wav_chunk(fin, "data", &len))
//{
// ods("[find_wav_chunk] \"data\" failed.\n");
// return 1;
//}
format.samplerate = 48'000;
format.channels = 2;
comments = ope_comments_create();
ope_comments_add(comments, "ARTIST", "Someone");
ope_comments_add(comments, "TITLE", "Some track");
enc = ope_encoder_create_file(out_file, comments, format.samplerate, format.channels, 0, &error);
if (!enc) {
char errbuf[2049];
sprintf_s(errbuf, "error encoding to file %s: %s\n", out_file, ope_strerror(error));
ope_comments_destroy(comments);
fclose(fin);
return 1;
}
while (1) {
short buf[2 * READ_SIZE];
int ret = fread(buf, 2 * sizeof(short), READ_SIZE, fin);
if (ret > 0) {
ope_encoder_write(enc, buf, ret);
}
else break;
}
ope_encoder_drain(enc);
ope_encoder_destroy(enc);
ope_comments_destroy(comments);
fclose(fin);
return 0;
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment