Send audio over skype call

一曲冷凌霜 提交于 2019-12-12 09:04:40

问题


I'm trying to send an audio file (or directly audio over current input device for skype) when I click a button on a windows form. I found some links but all references appear to be broken and I'm going mad on how to work with it.

I already manage to connect to skype api and use it (I already use it for other projects and it's working well), but I really can't send any audio over input audio stream.

Any suggestion will be appreciated.

Current code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Speech;
using System.Speech.Synthesis;
using SKYPE4COMLib;
using System.Reflection;
using System.IO;

namespace TestSendAudioOnSkype
{
    /// <summary>
    /// Logica di interazione per MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private Call CurrentCall = null;
        private Skype SkypeApplet;
        private const int SkypeProtocol = 9;

        private SpeechSynthesizer Speak = new SpeechSynthesizer();

        public MainWindow()
        {
            InitializeComponent();
            try
            {
                SkypeApplet = new Skype();
                SkypeApplet.Attach(SkypeProtocol, true);
                SkypeApplet.CallStatus += SkypeApplet_CallStatus;
                //CurrentCall = SkypeApplet.ActiveCalls[0];
            }
            catch (Exception e)
            {
                MessageBox.Show("errore: " + e.ToString());
                System.Windows.Application.Current.Shutdown();
            }
        }

        void SkypeApplet_CallStatus(Call pCall, TCallStatus Status)
        {
            if (Status == TCallStatus.clsInProgress)
                CurrentCall = pCall;
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            if (CurrentCall == null)
            {
                CurrentCall = SkypeApplet.ActiveCalls[1];
            }

            string path = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            string filepath = System.IO.Path.Combine(path,"tmp.wav");
            Speak.SetOutputToWaveFile(filepath);
            Speak.Speak("Hello world");
            Speak.SetOutputToDefaultAudioDevice();
            //Speak.SpeakAsync("Hello world");

            try
            {
                CurrentCall.set_OutputDevice(TCallIoDeviceType.callIoDeviceTypeFile, filepath);
                CurrentCall.set_InputDevice(TCallIoDeviceType.callIoDeviceTypeFile, filepath);
                System.Threading.Thread.Sleep(3000);
                CurrentCall.set_InputDevice(TCallIoDeviceType.callIoDeviceTypeFile, "");
                CurrentCall.set_OutputDevice(TCallIoDeviceType.callIoDeviceTypeFile, "");
                MessageBox.Show("invio terminato");
            }
            catch (Exception exc)
            {
                MessageBox.Show("errore: " + exc.ToString());
                //System.Windows.Application.Current.Shutdown();
            }
        }
    }
}

What I've found so far: http://community.skype.com/t5/Desktop-API-former-Public-API/Sending-Audio-in-Skype/td-p/422


回答1:


Looks like the problem is about the file format, not directly my code which should work.

This is what I got as an answer on skype forums: http://devforum.skype.com/t5/Developer-Corner/Skype4COM-and-C-Sending-audio-on-current-call-through-input/td-p/8414?utm_source=Subsciption&utm_medium=Subsciption&utm_campaign=Subsciption

It works, I built the file as a 16 Bit samples, 16khz, mono WAV file. Here is the code using System.Speech library: (Speak is a SpeechSynthesize object)

    Speak.SetOutputToWaveFile(filepath, new System.Speech.AudioFormat.SpeechAudioFormatInfo(
        16000,
        System.Speech.AudioFormat.AudioBitsPerSample.Sixteen,
        System.Speech.AudioFormat.AudioChannel.Mono
    ));

Hope this help



来源:https://stackoverflow.com/questions/8244530/send-audio-over-skype-call

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!