我想IRandomAccessStream在C#中实现一个实例(它将返回实时生成的数据).该流实际上不需要是可写的或可搜索的,但我想在ReadAsync方法中返回我自己的数据(实际上是其中的一部分IInputStream).
public IAsyncOperationWithProgress<IBuffer, uint> ReadAsync(IBuffer buffer, uint count, InputStreamOptions options)
{
throw new NotImplementedException("To be done");
}
Run Code Online (Sandbox Code Playgroud)
我的两个主要问题是:
IAsyncOperationWithProgress?框架中是否有任何内容可以帮助解决这个问题?IBuffer只有Length和Capacity属性(具体的Buffer类不再提供).在C#中将WAV文件转换为WMA(反之亦然)的最佳解决方案是什么?我实际上已经使用Windows Media Encoder SDK实现了这一点,但是至少可以说使用我的应用程序分发Windows Media Encoder是很麻烦的.Windows Media Format SDK将大部分API标记为已弃用.看起来可能有一些我可以在Windows SDK中使用的DirectX媒体对象(DMO),但是会有很多互操作要写.
我想知道是否有一个可以执行转换的非托管库的良好托管包装器.它需要一个许可证,允许它作为闭源商业应用程序的一部分进行分发.
在Visual Studio中,nupack添加了一个名为Package Manager Console的电源shell窗口.我认为这是运行源代码控制命令的好地方(我正在使用Mercurial).但是,默认工作目录是我的用户文件夹,因此每次加载新项目时都需要导航到我的代码文件夹.
我想知道是否有一个单行命令将工作目录设置为解决方案文件夹.例如,这样的事情存在吗?
cd $SolutionFolder
Run Code Online (Sandbox Code Playgroud)
从get-variable它的结果看起来没有任何立即可用的东西,但我以前从未使用过PowerShell,所以也许有办法获得解决方案文件夹?
我正在使用一些一次性.NET对象编写一些IronPython,并想知道是否有一种很好的"pythonic"方式.目前我有一堆finally语句(我想在每个语句中都应该检查None)或者如果构造函数失败,变量是否甚至不存在?)
def Save(self):
filename = "record.txt"
data = "{0}:{1}".format(self.Level,self.Name)
isf = IsolatedStorageFile.GetUserStoreForApplication()
try:
isfs = IsolatedStorageFileStream(filename, FileMode.Create, isf)
try:
sw = StreamWriter(isfs)
try:
sw.Write(data)
finally:
sw.Dispose()
finally:
isfs.Dispose()
finally:
isf.Dispose()
Run Code Online (Sandbox Code Playgroud) 我想用C#编写一个VoIP程序,其中我想自己编码/解码传出和传入的流.如果你能告诉我,我可以使用哪个库,我会在哪里可以找到该库,我将不胜感激.
我可能有点懒,在这里问这个,但我刚开始使用LINQ而且我有一个函数,我确信可以变成两个LINQ查询(或一个嵌套查询)而不是一个LINQ和一对foreach陈述.作为一个例子,任何LINQ大师都会关心为我重构这个吗?
函数本身循环遍历.csproj文件列表,并拉出项目中包含的所有.cs文件的路径:
static IEnumerable<string> FindFiles(IEnumerable<string> projectPaths)
{
string xmlNamespace = "{http://schemas.microsoft.com/developer/msbuild/2003}";
foreach (string projectPath in projectPaths)
{
XDocument projectXml = XDocument.Load(projectPath);
string projectDir = Path.GetDirectoryName(projectPath);
var csharpFiles = from c in projectXml.Descendants(xmlNamespace + "Compile")
where c.Attribute("Include").Value.EndsWith(".cs")
select Path.Combine(projectDir, c.Attribute("Include").Value);
foreach (string s in csharpFiles)
{
yield return s;
}
}
}
Run Code Online (Sandbox Code Playgroud) 我目前正在开发一种应用程序,它需要传输编码为特定音频格式的语音.
System.Speech.AudioFormat.SpeechAudioFormatInfo synthFormat =
new System.Speech.AudioFormat.SpeechAudioFormatInfo(System.Speech.AudioFormat.EncodingFormat.Pcm,
8000, 16, 1, 16000, 2, null);
Run Code Online (Sandbox Code Playgroud)
这表明音频采用PCM格式,每秒8000个采样,每个采样16位,单声道,每秒16000个平均字节,块对齐为2.
当我尝试执行以下代码时,没有任何内容写入我的MemoryStream实例; 但是,当我从每秒8000个样本更改为11025时,音频数据被成功写入.
SpeechSynthesizer synthesizer = new SpeechSynthesizer();
waveStream = new MemoryStream();
PromptBuilder pbuilder = new PromptBuilder();
PromptStyle pStyle = new PromptStyle();
pStyle.Emphasis = PromptEmphasis.None;
pStyle.Rate = PromptRate.Fast;
pStyle.Volume = PromptVolume.ExtraLoud;
pbuilder.StartStyle(pStyle);
pbuilder.StartParagraph();
pbuilder.StartVoice(VoiceGender.Male, VoiceAge.Teen, 2);
pbuilder.StartSentence();
pbuilder.AppendText("This is some text.");
pbuilder.EndSentence();
pbuilder.EndVoice();
pbuilder.EndParagraph();
pbuilder.EndStyle();
synthesizer.SetOutputToAudioStream(waveStream, synthFormat);
synthesizer.Speak(pbuilder);
synthesizer.SetOutputToNull();
Run Code Online (Sandbox Code Playgroud)
使用8000的采样率时没有记录异常或错误,我在关于SetOutputToAudioStream的文档中找不到任何有用的东西,为什么它以每秒11025个样本而不是8000成功.我有一个涉及wav文件的解决方法,我使用一些声音编辑工具生成并转换为正确的采样率,但如果可以的话,我想从应用程序中生成音频.
一个特别的兴趣点是SpeechRecognitionEngine接受该音频格式并成功识别出我的合成波形文件中的语音...
更新:最近发现这种音频格式对某些已安装的声音成功,但对其他声音失败.它专门针对LH Michael和LH Michelle而失败,并且针对PromptBuilder中定义的某些语音设置的失败会有所不同.
您是否知道可以在Silverlight中使用的任何好的纪律或免费音频/声音组件(在客户端更好)?
所需功能:
我找到的一些有用的项目:
Saluse MediaKit for Silverlight(MP3解码器,AudioPreProcessor,可视化器,效果)
说我正在使用WPF或Silverlight并将ContentPresenter绑定到整数属性:
<ContentPresenter Content={Binding Score} />
Run Code Online (Sandbox Code Playgroud)
如果得分为10,我想显示金星,否则只显示数字.基本上我有两个可能的数据模板:
<Path Fill="Gold" Data="..." />
<TextBlock Text="{Binding Score}" />
Run Code Online (Sandbox Code Playgroud)
设置它的最佳方法是什么?是否使用绑定转换器?或者绑定到另一个动态加载相应数据模板xaml的对象,并根据Score的值生成正确的FrameworkElement?或者是否有另外一个我缺少的技巧 - 也许ContentPresenter不是正确使用的控件?
我想知道你是否可以做这样的事情,但它不喜欢ContentTemplate值中的嵌套绑定:
<StackPanel>
<StackPanel.Resources>
<DataTemplate x:Key="LowScore">
<TextBlock Text="{Binding Path=Score}" Foreground="Red" />
</DataTemplate>
<DataTemplate x:Key="HighScore">
<Path Fill="Gold" Data="M 0,0 l 10,0 l 5,-10 l 5,10 l 10,0 l -7,10 l 2,10 l -10,-5 l -10,5 l 2,-10 Z" />
</DataTemplate>
</StackPanel.Resources>
<ContentPresenter Content="{Binding Score}" ContentTemplate="{StaticResource ResourceKey={Binding ScoreTemplate}}">
</ContentPresenter>
</StackPanel>
Run Code Online (Sandbox Code Playgroud) 如果我定义了以下样式:
<UserControl.Resources>
<Style TargetType="TextBlock" x:Key="ProblemStyle">
<Setter Property="FontSize" Value="40"/>
<Setter Property="FontWeight" Value="Bold"/>
</Style>
</UserControl.Resources>
Run Code Online (Sandbox Code Playgroud)
然后,当我将ContentPresenter数据绑定到字符串时,在WPF中我可以使用以下XAML根据需要设置文本样式:
<ContentPresenter Content="{Binding Problem}">
<ContentPresenter.Resources>
<Style TargetType="TextBlock" BasedOn="{StaticResource ProblemStyle}" />
</ContentPresenter.Resources>
</ContentPresenter>
Run Code Online (Sandbox Code Playgroud)
但是,在Silverlight中,这不起作用.有没有办法适用于两者?
audio ×4
c# ×4
silverlight ×3
.net ×2
wpf ×2
components ×1
data-binding ×1
datatemplate ×1
ironpython ×1
libraries ×1
linq ×1
linq-to-xml ×1
nuget ×1
powershell ×1
python ×1
streaming ×1
styles ×1
textblock ×1
using ×1
voip ×1
wma ×1