diff --git a/NoobDevBot(Stream)/App.config b/NoobDevBot(Stream)/App.config new file mode 100644 index 0000000..9fed51c --- /dev/null +++ b/NoobDevBot(Stream)/App.config @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/NoobDevBot(Stream)/NoobDevBot(Stream).csproj b/NoobDevBot(Stream)/NoobDevBot(Stream).csproj new file mode 100644 index 0000000..6e93129 --- /dev/null +++ b/NoobDevBot(Stream)/NoobDevBot(Stream).csproj @@ -0,0 +1,91 @@ + + + + + Debug + AnyCPU + {27A6E8B1-F7C7-4CB7-AE69-E240ED7D9971} + Exe + Properties + NoobDevBot + NoobDevBot + v4.6 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\NAudio.1.7.3\lib\net35\NAudio.dll + True + + + ..\packages\NAudio.Lame.1.0.4\lib\net20\NAudio.Lame.dll + True + + + ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll + True + + + + + ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll + True + + + + + + + + + + + ..\packages\Telegram.Bot.10.3.1\lib\net46\Telegram.Bot.dll + True + + + + + + + + + + + + + Always + + + Always + + + + + \ No newline at end of file diff --git a/NoobDevBot(Stream)/Program.cs b/NoobDevBot(Stream)/Program.cs new file mode 100644 index 0000000..fe69a06 --- /dev/null +++ b/NoobDevBot(Stream)/Program.cs @@ -0,0 +1,99 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Telegram.Bot; +using Telegram.Bot.Args; +using Telegram.Bot.Types; +using Telegram.Bot.Types.ReplyMarkups; +using System.Speech.Synthesis; +using System.Speech.AudioFormat; +using System.Media; +using System.IO; +using NAudio.Wave; +using NAudio.Lame; + +namespace NoobDevBot +{ + class Program + { + static TelegramBotClient bot; + static ReplyKeyboardMarkup markup; + static SpeechSynthesizer spsy; + + static void Main(string[] args) + { + bot = new TelegramBotClient("232609616:AAGOJkDYQmSmUFhjToCt3JTtRnlWp3-TszE"); + markup = new ReplyKeyboardMarkup(); + spsy = new SpeechSynthesizer(); + + keyboard(); + bot.OnMessage += bot_OnMessage; + + bot.StartReceiving(); + + + + + + Console.ReadKey(); + } + + private static async void bot_OnMessage(object sender, MessageEventArgs e) + { + Console.WriteLine($"{e.Message.From.Username ?? e.Message.From.FirstName}: {e.Message.Text}"); + switch (e.Message.Text) + { + case "/nextStream": await bot.SendTextMessageAsync(e.Message.Chat.Id, DateTime.UtcNow.ToLongDateString(), replyMarkup: markup); break; + case "/sayHello": await bot.SendTextMessageAsync(e.Message.Chat.Id, $"Hallo {e.Message.From.Username ?? e.Message.From.FirstName}", replyMarkup: markup); break; + case "/speakHello": + + using (var stream = new MemoryStream()) + { + using (var outStream = new MemoryStream()) + { + + string filename = e.Message.From.Username ?? e.Message.From.FirstName + ".mp3"; + spsy.SetOutputToAudioStream(stream, new SpeechAudioFormatInfo(44100, AudioBitsPerSample.Sixteen, AudioChannel.Mono)); + + spsy.Speak($"Hallo {e.Message.From.Username ?? e.Message.From.FirstName}"); + stream.Position = 0; + int seconds; + WaveFormat format = new WaveFormat(44100, 1); + using (var mp3file = new LameMP3FileWriter(outStream, format, 128)) + { + stream.CopyTo(mp3file); + //((stream.Length) / (sampleRate * (bitRate / 8))) / channels + seconds = (int)(stream.Length / (44100 * 2)); //(int)wavefile.CurrentTime.TotalSeconds; + } + + outStream.Position = 0; + FileToSend fts = new FileToSend("Hello.mp3", outStream); + + await bot.SendAudioAsync(e.Message.Chat.Id, fts, seconds, "Cortana", "Hallo"); + + } + } + break; + default: await bot.SendTextMessageAsync(e.Message.Chat.Id, "I don't know, what do to with this command. Plase be so kind to use the keyboard, so you don't enter the wrong commands. Thank you very much.", replyMarkup: markup); break; + } + + } + + private static void keyboard() + { + var button00 = new KeyboardButton(); + button00.Text = "/sayHello"; + var button01 = new KeyboardButton(); + button01.Text = "/nextStream"; + var button02 = new KeyboardButton(); + button02.Text = "/speakHello"; + markup.Keyboard = new KeyboardButton[1][]; + markup.Keyboard[0] = new KeyboardButton[3]; + markup.Keyboard[0][0] = button00; + markup.Keyboard[0][1] = button01; + markup.Keyboard[0][2] = button02; + } + } +} diff --git a/NoobDevBot(Stream)/Properties/AssemblyInfo.cs b/NoobDevBot(Stream)/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..180a66d --- /dev/null +++ b/NoobDevBot(Stream)/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Allgemeine Informationen über eine Assembly werden über die folgenden +// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, +// die einer Assembly zugeordnet sind. +[assembly: AssemblyTitle("NoobDevBot")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("NoobDevBot")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar +// für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von +// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen. +[assembly: ComVisible(false)] + +// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird +[assembly: Guid("27a6e8b1-f7c7-4cb7-ae69-e240ed7d9971")] + +// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: +// +// Hauptversion +// Nebenversion +// Buildnummer +// Revision +// +// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern +// übernehmen, indem Sie "*" eingeben: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/NoobDevBot(Stream)/packages.config b/NoobDevBot(Stream)/packages.config new file mode 100644 index 0000000..32f5ac7 --- /dev/null +++ b/NoobDevBot(Stream)/packages.config @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/NoobDevBot.sln b/NoobDevBot.sln index 153964d..f7e9f43 100644 --- a/NoobDevBot.sln +++ b/NoobDevBot.sln @@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 VisualStudioVersion = 14.0.25420.1 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NoobDevBot", "NoobDevBot\NoobDevBot.csproj", "{27A6E8B1-F7C7-4CB7-AE69-E240ED7D9971}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NoobDevBot(Stream)", "NoobDevBot(Stream)\NoobDevBot(Stream).csproj", "{27A6E8B1-F7C7-4CB7-AE69-E240ED7D9971}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NoobDevBot", "NoobDevBot\NoobDevBot.csproj", "{8CD55321-6BE8-4958-864F-64749D0008A5}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,6 +17,10 @@ Global {27A6E8B1-F7C7-4CB7-AE69-E240ED7D9971}.Debug|Any CPU.Build.0 = Debug|Any CPU {27A6E8B1-F7C7-4CB7-AE69-E240ED7D9971}.Release|Any CPU.ActiveCfg = Release|Any CPU {27A6E8B1-F7C7-4CB7-AE69-E240ED7D9971}.Release|Any CPU.Build.0 = Release|Any CPU + {8CD55321-6BE8-4958-864F-64749D0008A5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8CD55321-6BE8-4958-864F-64749D0008A5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8CD55321-6BE8-4958-864F-64749D0008A5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8CD55321-6BE8-4958-864F-64749D0008A5}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/NoobDevBot/App.config b/NoobDevBot/App.config index 8324aa6..9fed51c 100644 --- a/NoobDevBot/App.config +++ b/NoobDevBot/App.config @@ -1,6 +1,14 @@ - + + + + + + + + + \ No newline at end of file diff --git a/NoobDevBot/NoobDevBot.csproj b/NoobDevBot/NoobDevBot.csproj index c90de23..795753d 100644 --- a/NoobDevBot/NoobDevBot.csproj +++ b/NoobDevBot/NoobDevBot.csproj @@ -4,7 +4,7 @@ Debug AnyCPU - {27A6E8B1-F7C7-4CB7-AE69-E240ED7D9971} + {8CD55321-6BE8-4958-864F-64749D0008A5} Exe Properties NoobDevBot @@ -33,14 +33,35 @@ 4 + + ..\packages\NAudio.1.7.3\lib\net35\NAudio.dll + True + + + ..\packages\NAudio.Lame.1.0.4\lib\net20\NAudio.Lame.dll + True + + + ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll + True + + + ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll + True + + + + ..\packages\Telegram.Bot.10.3.1\lib\net46\Telegram.Bot.dll + True + @@ -48,6 +69,15 @@ + + + + + Always + + + Always +